饿汉式
class Single类已加载对象就已经存在了
{
private static Single s = new Single();
private Single(){}
public static Single getInstance()
{
return s;
}
}
懒汉式
class single2类加载进来,没有对象,只有调用了getInstance方法时,才会创建对象
延迟加载形式
{
private static Single2 s = null;
private Single2(){}
public static Single2 getInstance()
{
if(s==null)
s = new single2();
return s;
}
|
|