单例的LazyHolder写法

参考 Android 的com.android.server.webkit.SystemImpl 的写法

public class SystemImpl implements SystemInterface {
    // Initialization-on-demand holder idiom for getting the WebView provider packages once and
    // for all in a thread-safe manner.  是线程安全的。
    private static class LazyHolder {
        private static final SystemImpl INSTANCE = new SystemImpl();
    }
    public static SystemImpl getInstance() {
        return LazyHolder.INSTANCE;
    }
    private SystemImpl() {
        //初始化
    }
}
posted @ 2020-01-09 10:33  gregpeng  阅读(626)  评论(0编辑  收藏  举报