标签:
推荐使用方法:
public static class Singleton{
private static final Singleton instance = new Singleton();
private Singleton(){
}
public static Singleton getInstance(){
return instance;
}
}
线程不安全:(加上synchronized也不够好):
public static class Singleton{
private static Singleton instance = null;
private Singleton(){
}
public static Singleton getInstance(){
if(instance == null){
instance = new Singleton();
}
return instance;
}
}
标签:
原文地址:http://www.cnblogs.com/wangqian-easy/p/4860474.html