黑马程序员 延迟加载的单例设计模式
上一篇 /
下一篇 2014-07-08 14:03:16
/ 个人分类:java知识
单例设计模式:要求内存中只能存在一个对象,不能用new方法创建对象 ,只能用类名调用静态方法产生对象。
class single{
private single(){};
private static single s=null;
public static single getinstance()
{
if(s==null)
synchronized (single.class){
if(s==null)
s=new single();
}
return s;
}
}
class singleDemo
{
public static void main(String[] args)
{
single ss=single.getinstance();
ss.getinstance();
}
}
收藏
举报
TAG: