但是如果两个对象均由反射方法创建呢?
public static void main(String[] args) throws Exception {
//创建对象1和2,通过反射获得构造方法的newInstance()方法
Constructor constructor = TCLLazyMan.class.getDeclaredConstructor(null);
constructor.setAccessible(true);
TCLLazyMan instance1 = (TCLLazyMan)constructor.newInstance();
TCLLazyMan instance2 = (TCLLazyMan)constructor.newInstance();
//输出结果:instance1和instance2相等吗? false
System.out.println("instance1和instance2相等吗? " + (instance1 == instance2));
}
/*
结果分析:
三重检测防止不了反射破坏类的唯一性
*/