日期:2014-05-20 浏览次数:20702 次
import java.lang.reflect.Method;
class HelloWorld {
@SuppressWarnings("unused")
private void sayHello() {
System.out.println("私有方法也是可以调用的!");
}
}
public class PrivateReflect {
public static void main(String args[]) throws Throwable {
HelloWorld hello = new HelloWorld();
Method helloMethod = HelloWorld.class.getDeclaredMethod("sayHello");
helloMethod.setAccessible(true);
helloMethod.invoke(hello);
}
}