/** * Created by chao on 2017/9/4. * 懒汉式 */ public class Singleton { private static Singleton instrance; private Singleton(){} public static synchronized Singleton getInstrance(){ if (instrance==null){ instrance = new Singleton(); } return instrance; } } /** * Created by chao on 2017/9/4. * 恶汉式 */ public class Singleton{ private static Singleton instrance = new Singleton(); private Singleton(){} public static Singleton getInstrance(){ return instrance; } }
单例模式
最新推荐文章于 2025-05-23 19:33:43 发布
1519

被折叠的 条评论
为什么被折叠?



