public static factory method

后端 未结 5 407
灰色年华
灰色年华 2020-12-29 07:08

First of all please forgive me if its a really dumb question, I am just trying to learn this language to its core. I am reading Effective Java and the very first chapter tal

5条回答
  •  清歌不尽
    2020-12-29 07:22

    When you use the new keyword then you as the developer know that the JDK will create a new instace of that object. What the author is saying, when you use a static method, the developer no longer knows if the method is creating a new instance or possibly doing something else. Something else can be, reusing cached data, object pooling, creating a private implementation and returning a subclass of the class.

提交回复
热议问题