It's possible using reflection, although you should probably question your design somewhat if you need that sort of behavior. Class.getMethod
takes a String
for the method name and returns a Method
object, which you can then call .invoke
on to call the method
These Javadoc pages should be helpful:
Sample code (assuming the yyyyyy
methods take one int
argument, just to show argument passing):
yyyyyy obj = new yyyyyy();
String[] methodNames = {"foo", "bar", "baz"};
for(String methodName : methodNames) {
Method method = Class.forName("yyyyyy").getMethod(methodName, new Class[] {int.class});
method.invoke(obj, 4); // 4 is the argument to pass to the method
}