静态检测单例模式

调用静态内部类,同样是线程安全的,原理同饿汉式单例

package org.study.singleton;

/**
 * 静态检测单例模式
 *
 *
 */
public class StaticCheckSingleton {

    private static class LazyHolder {
        private static final StaticCheckSingleton INSTANCE = new StaticCheckSingleton();
    }

    private StaticCheckSingleton(){};

    private static final StaticCheckSingleton getInstance() {
        return LazyHolder.INSTANCE;
    }

}


posted @ 2021-03-06 23:13  Leo-Wong  阅读(40)  评论(0编辑  收藏  举报