I have the name of a clas.s and the name of the method in it - in a
String format. How to call this method with jdk 1.5.
/**
* params can be null.
*/
public void call(String clazz, String method, String [] params ){
}
Thanks
Oliver Wong - 18 Aug 2006 16:47 GMT
>I have the name of a clas.s and the name of the method in it - in a
> String format. How to call this method with jdk 1.5.
[quoted text clipped - 4 lines]
>
> }
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html
in particular forName(String), getMethods().
- Oliver
Arne Vajhøj - 19 Aug 2006 00:58 GMT
> I have the name of a clas.s and the name of the method in it - in a
> String format. How to call this method with jdk 1.5.
[quoted text clipped - 5 lines]
>
> }
Example (from so code I had):
public static void c(Object o, String methodName, String a, String b) {
try {
Class declarg[] = new Class[2];
declarg[0] = String.class;
declarg[1] = String.class;
Method m = o.getClass().getMethod(methodName, declarg);
Object callarg[] = new Object[2];
callarg[0] = a;
callarg[1] = b;
m.invoke(o, callarg);
} catch (Exception e) {
}
}
Arne