懒汉式单列

来源:互联网 发布:雕刻机路径编程软件 编辑:程序博客网 时间:2024/06/06 00:24

public class LazySingLeton {


    //懒汉式单列模式


    //比较懒,在加载时不创建实例,因此类加载速度快,但在运 


    行获取对象的速度慢


   private static LazySingLeton instance=null;   

 

   //私有静态成员,并不初始化


   private LazySingLeton() {


   //私有构造函数


   }


   public static LazySingLeton getInstance() {


       if(instance==null) {


            instance=new LazySingLeton();


       }


   return instance;


   }


}