110,534
社区成员
发帖
与我相关
我的任务
分享
public class A
{
private static A _A;
private A(){}
public static A CreateA()
{
_A = new A();
return _A;
}
}
http://msdn.microsoft.com/zh-cn/library/c5kehkcz.aspx
public class A {
private A() {
}
}
public final class B {
public static A createA() throws SecurityException, NoSuchMethodException,
IllegalArgumentException, InstantiationException,
IllegalAccessException, InvocationTargetException {
Constructor<A> constructor = null;
try {
Class<A> clazz = A.class;
constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
return constructor.newInstance();
} finally {
if (constructor != null) {
constructor.setAccessible(false);
}
}
}
public static void main(String[] args) throws InstantiationException,
IllegalAccessException, SecurityException, NoSuchMethodException,
IllegalArgumentException, InvocationTargetException {
System.out.println(B.createA().hashCode());
}
}