//Single类一进内存,就已经创建好了对象。
class Single
{
private static Single s = new Single();
private Single(){}
public static Single getInstance(){
return s;
}
}
//Single类进内存,对象还没有存在,只有调用了getInstance方法时,才建立对象。
class Single
{
private static Single s = null;
private Single(){}
public static Single getInstance(){
if(s==null)
{
synchronized(Single.class){
if(s==null){
s = new Single();
}
}
return s;
}
}
}
原文:https://www.cnblogs.com/hen-java/p/12600590.html