import java.lang.reflect.InvocationTargetException;
public class TestInvocation {
public void getStr(String str){
System.out.println(str);
}
public void getStr(String str1,String str2){
System.out.println(str1);
System.out.println(str2);
}
public static void main(String[] args) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
TestInvocation ti=TestInvocation.class.newInstance();
TestInvocation.class.getMethod("getStr", String.class).invoke(ti, "123");
TestInvocation.class.getMethod("getStr", new Class<?>[] {String.class,String.class}).invoke(ti, new Object[] {"123","456"});
}
}
转载于:https://my.oschina.net/findurl/blog/3092629