import java.lang.reflect.Method;
public class DumpMethod {
public int add(int a, int b) {
return a + b;
}
public String echo(String message) {
return "Hello" + " " + message;
}
public static void main(String[] args) throws Exception {
Class<?> classType = DumpMethod.class;
Object dumpMethod = classType.newInstance();
Method addMethod = classType.getMethod("add", new Class[] { int.class,
int.class });
Object result = addMethod.invoke(dumpMethod, new Object[] { 1, 2 });
System.out.println((Integer) result);
System.out.println("------------------------------");
Method echoMethod = classType.getMethod("echo",
new Class[] { String.class });
Object result2 = echoMethod.invoke(dumpMethod, new Object[] { "Tom" });
System.out.println((String) result2);
}
}