一. 懒汉式单例

//懒汉式单例类.在第一次调用的时候实例化自己 
public class Singleton {
    private Singleton() {}
    private static Singleton single=null;
    //静态工厂方法 
    public static Singleton getInstance() {
         if (single == null) {  
             single = new Singleton();
         }  
        return single;
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2022-02-27
  • 2022-12-23
  • 2021-06-25
  • 2021-06-22
  • 2021-06-30
  • 2022-03-08
  • 2021-06-24
猜你喜欢
  • 2021-06-18
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2021-04-27
  • 2021-06-28
  • 2022-12-23
相关资源
相似解决方案