1)饿汉式
private Single(){}
private static final Single s = new Single();
public static Single getInstance()
{
return s;
}
2)懒汉式:延迟加载
private Single(){}
private static final Single s = null;
public static synchronized Single getInstance()
{
if(s==null)
s = new Single();
return s;
}
|