How to instantiate a Singleton multiple times?

后端 未结 9 1896
醉酒成梦
醉酒成梦 2020-12-19 04:08

I need a singleton in my code. I implemented it in Java and it works well. The reason I did it, is to ensure that in a mulitple environment, there is only one instance of th

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 04:55

    A singleton, by definition, can only be instantiated once. However, the fact that your unit test requires two singletons is a strong indication that your object shouldn't really be a singleton, and that you should rethink the singleton design.

提交回复
热议问题