看到楼下同学的评论,我测试了一下好像反射并不能调用私有方法吧
public class TestClass {
private void print(int a,int b){
System.out.println(a+b);
}
}
......
Class c = Class.forName("com.reflect.TestClass");
Method m = c.getDeclaredMethod("print", int.class,int.class);
m.invoke(new TestClass(), 3,5);
......
priavate情况下会报错
public class TestClass {
private void print(int a,int b){
System.out.println(a+b);
}
}
......
Class c = Class.forName("com.reflect.TestClass");
Method m = c.getDeclaredMethod("print", int.class,int.class);
m.invoke(new TestClass(), 3,5);
......
priavate情况下会报错
2016-09-24