Regarding static holder singleton pattern

后端 未结 2 806
无人及你
无人及你 2020-12-01 08:01

I have developed singleton in many ways depending upon the condition like volatile/lazy singleton, eager singleton, normal singleton and through Enum also, but specifically

2条回答
  •  温柔的废话
    2020-12-01 08:29

    This is a way to make a thread-safe lazy singleton by exploiting the way how JVM loads classes. You can read more about why and how to correctly implement it in Bloch's Effective Java book.

    Remember, that from the testable code point of view singletons (and global state in general) are not beneficial and should be avoided.

提交回复
热议问题