- 1 /**
- 2 * 单例模式:懒汉式
- 3 * 是否Lazy初始化:是
- 4 * 是否多线程安全:否
- 5 */
- 6 public class Singleton {
- 7
- 8 private static Singleton singleton;
- 9
- 10 // 构造器私有
- 11 private Singleton() {
- 12
- 13 }
- 14
- 15 // 实例方法
- 16 public static Singleton getInstance() {
- 17 if (singleton == null) {
- 18 return new Singleton();
- 19 }
- 20 return singleton;
- 21 }
- 22 }