Java的设计模式————单例

单例模式分为:懒汉式(线程不安全),懒汉式(线程安全),饿汉式,双重加锁式,登记式,枚举

懒汉式(线程不安全)

public class LazySingleton {
            
        public static  LazySingleton  instance;
        private LazySingleton() {}
        public static LazySingleton  getInstance() {
            if(instance==null) {
                instance=new LazySingleton();
            }
            return instance;
        }
}

猜你喜欢

转载自www.cnblogs.com/zilvderen/p/12053091.html