Static factory methods vs Instance (normal) constructors?

前端 未结 11 1480
醉梦人生
醉梦人生 2020-12-02 12:16

In a language where both are available, would you prefer to see an instance constructor or a static method that returns an instance?

For example, if you\'re creating

11条回答
  •  清歌不尽
    2020-12-02 12:45

    Static Method. Then you can return a null, rather than throwing an exception (unless a reference type)

提交回复
热议问题