Via Reflection you can get access to a Class's Methods - see
http://java.sun.com/docs/books/tutorial/reflect/member/methodInvocation.html
and
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Method.html
However, you have to pass in an instance of that class as well as the arguments. You could create a simple wrapper class, though, something like
class MethodInvoker{
private Object o;
private String methodName;
public MethodInvoker(Object o, String methodName){
this.o=o;
this.methodName=methodName;
}
public Object invoke(Object[] args) throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{
Class[] paramTypes = new Class[args.length];
for(int i=0;i<paramTypes.length;i++){
paramTypes[i] = args[i].getClass();
}
return o.getClass().getMethod(methodName, paramTypes).invoke(o, args);
}
}
Be careful, though, as this would not work with any null parameters.