//单例模式,饿汉式 public class Singleton { //私有化构造器 private Singleton(){} private static Singleton instance=new Singleton(); //实例化对象 //创建静态方法,以便调用 public static Singleton getInstance(){ return instance; } }
单例模式,饿汉式
最新推荐文章于 2024-07-12 17:06:20 发布
//单例模式,饿汉式 public class Singleton { //私有化构造器 private Singleton(){} private static Singleton instance=new Singleton(); //实例化对象 //创建静态方法,以便调用 public static Singleton getInstance(){ return instance; } }