Hiding a constructor behind a static creator method?

前端 未结 9 1595
我在风中等你
我在风中等你 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:01

    Well it would be possible for SomeClass.create() to pull an instance from a cache. new SomeClass() won't do that without some shenanigans.

    It would be also be possible for create() to return any number of implementations of SomeClass. Basically, a Factory type of dealio.

提交回复
热议问题