面试遇到过几次让手写单例模式,无论是写得懒汉,恶汉式最终都会引导你写双重检查的单例模式;so双重检测的单例!!
package one;
/*单利模式*/
public class SingleTon {
private SingleTon(){}
private static volatile SingleTon singleTon;
public SingleTon getInstance(){
if(singleTon==null){
synchronized (SingleTon.class){
if (singleTon==null){
singleTon = new SingleTon();
}
}
}
return singleTon;
}
}