我想问一下为什么我这样写显示s3不等于s4
public class LazySingleton {
private LazySingleton() {
}
private static LazySingleton instance;
public static LazySingleton getInstance() {
if(instance == null)
{
return new LazySingleton();
}else {
return instance;
}
}
}你只return没先赋值,肯定不一样了,第一个return前赋值,加这句instance=new LazySingleton()。