Hiding a constructor behind a static creator method?

前端 未结 9 1600
我在风中等你
我在风中等你 2021-01-04 00:47

I\'ve recently discovered an interesting way to create a new instance of an object in Google Guava and Project Lombok: Hide a constructor behind a static creator method. Thi

9条回答
  •  执念已碎
    2021-01-04 01:02

    Although not applicable to this particular code example, the practice of hiding the constructor behind a static method is Singleton Pattern. This is used when you want to ensure that a single instance of the class is created and used throughout.

提交回复
热议问题