本帖最后由 ㄨ____陌生 于 2013-4-1 21:35 编辑
懒汉式
class Single{
private static Single s=null;
private Single(){}
public static Single getInstance(){
if(s==null){
synchonized(Single.class){
s=new Single();
}
}
return s;
}
}
饿汉式
class Single{
private static final Single s=new Single();
private Single(){}
public static Single getInstance(){
return s;
}
}
|