单例模式1

饿汉式,静态成员变量方式

class Singleton{
  private Singleton(){}
  private static Singleton instance = new Singleton();
  public Singleton getInstance(){
    return instance;            
  }      
}

 

posted @ 2021-11-09 13:41  LinAlex  阅读(23)  评论(0)    收藏  举报