标签:final java 单例 single return public nal 效率 let 参考
参考:https://www.cnblogs.com/ngy0217/p/9006716.html
饿汉式(线程安全,调用效率高,但不能延时加载):
public class ImageLoader{ private static ImageLoader instance = new ImageLoader; private ImageLoader(){} public static ImageLoader getInstance(){ return instance; } }
懒汉式:静态内部类实现模式(线程安全,调用效率高,可以延时加载)
public class SingletonDemo3 { private static class SingletonClassInstance{ private static final SingletonDemo3 instance=new SingletonDemo3(); } private SingletonDemo3(){} public static SingletonDemo3 getInstance(){ return SingletonClassInstance.instance; } }
标签:final java 单例 single return public nal 效率 let 参考
原文地址:https://www.cnblogs.com/linwenbin/p/14489714.html