public class TestReflect {
public int sum(int m,int n){
return m+n;
}
public String say(String name){
return name+": haha!";
}
public static void main(String[] args) throws Exception {
Class cla = TestReflect.class;
Method sumMethod = cla.getMethod("sum", new Class[]{int.class,int.class});
int sum = (Integer) sumMethod.invoke(cla.newInstance(), new Object[]{1,2});
Method sayMethod = cla.getMethod("say", new Class[]{String.class});
String word = (String) sayMethod.invoke(cla.newInstance(), new Object[]{"I"});
System.out.println(sum);
System.out.println(word);
}
}