Correct implementation of initialization-on-demand holder idiom

前端 未结 3 1007
轮回少年
轮回少年 2020-12-10 12:36

I have got two versions of \"Initialization-on-demand holder idiom\":

  1. http://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom
  2. http://en.wik
3条回答
  •  一个人的身影
    2020-12-10 13:21

    private static class LazyHolder {
        $VISIBILITY static final Singleton INSTANCE = new Singleton();
    

    From a consumer's point of view it does not really matter if $VISIBILITY is public or private because the LazyHolder type is private. The variable is only accessible via the static method in both cases.

提交回复
热议问题