单例模式代码:
懒汉式:
class Single{
private static Single s = null;
private Single(){}
public static Single getIntance(){
if (s == null){
s = new Single();
}
return s;
}
}
饿汉式:
class Single{
private static Single s = new Single();
private Single(){}
public static Single getIntance(){
return s;
}
} |
|