单例模式分为:懒汉式(线程不安全),懒汉式(线程安全),饿汉式,双重加锁式,登记式,枚举
懒汉式(线程不安全)
public class LazySingleton { public static LazySingleton instance; private LazySingleton() {} public static LazySingleton getInstance() { if(instance==null) { instance=new LazySingleton(); } return instance; } }