单例的最佳实现方式

来源:互联网 发布:淘宝牙齿矫正器 编辑:程序博客网 时间:2024/04/28 22:13

public class Singleton {    // Private constructor prevents instantiation from other classes    private Singleton() { }    /**    * SingletonHolder is loaded on the first execution of Singleton.getInstance()     * or the first access to SingletonHolder.INSTANCE, not before.    */    private static class SingletonHolder {             public static final Singleton INSTANCE = new Singleton();    }    public static Singleton getInstance() {            return SingletonHolder.INSTANCE;    }}

0 0
原创粉丝点击