Java dynamic function calling

You can, using reflection. It is done by calling Yyyy.class.getMethod("methodName").invoke(someArgs)

You’d have to handle a bunch of exceptions, and your method must be public. Note that java coding conventions prefer methodName to method_name.

Using reflection, however, should be a last resort. You should be using more object-oriented techniques.

If you constantly need similar features, perhaps you can look at some dynamic language running on the java platform, like Groovy

Leave a Comment