//单例模式,饿汉式 public class Singleton { //私有化构造器 private Singleton(){} private static Singleton instance=new Singleton(); //实例化对象 //创建静态方法,以便调用 public static Singleton getInstance(){ return instance; } }
//单例模式,饿汉式 public class Singleton { //私有化构造器 private Singleton(){} private static Singleton instance=new Singleton(); //实例化对象 //创建静态方法,以便调用 public static Singleton getInstance(){ return instance; } }