[url=http://www.programfan.com/club/showpost.asp?id=9550]原文链接[/url]
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
public class AccessHello {
public static void main(String[] args) throws Exception {
Class<?> c = Class.forName("jbbtlh.jbb.tlh.reflect.Hello");
Constructor<?>[] con = c.getDeclaredConstructors();
con[0].setAccessible(true);
Object obj = con[0].newInstance();
Method method = c.getDeclaredMethod("f");
method.invoke(obj);
}
}
class Hello {
private Hello() {
}
public void f() {
System.out.println("******");
}
}