package reflect;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) throws IllegalAccessException,
IllegalArgumentException, InvocationTargetException,
NoSuchMethodException, SecurityException {
// TODO Auto-generated method stub
Test t = new Test();
Method createBondMethod = Test.class.getMethod("t",boolean.class);
Boolean returnValue = (Boolean) createBondMethod.invoke(t,true);
Method m2 = Test.class.getMethod("t4",new Class[]{String.class,int.class}); //注意传参的方式
m2.invoke(t,new Object[]{"liu",234});
}
private static class Test {
public void t(String t) {
System.out.println("15-------------" + t);
}
public void t(boolean b){
System.out.println("29-------------");
}
public void t() {
System.out.println("28-------------");
}
public void t4(String s1,int s2){
System.out.println("49-------------" + s1 + ": "+s2);
}
}
}
@CallerSensitive
public Method getMethod(String name, Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException {
return getMethod(name, parameterTypes, true);
}