- 章节名：ITEM 1: CONSIDER STATIC FACTORY METHODS INSTEAD OF CONSTRUCTORS
- 页码：第10页 2016-07-15 11:19:48
Here are some common names for static factory methods: - valueOf--Returns an instance that has, loosely speaking, the same value as its parameters. Such static factories are effectively type-conversion methods. - of--A concise alternative to valueOf, popularized by EnumSet. - getInstance--Returns an instance that is described by the parameters but cannot be said to have the same value. In the case of a singleton, getInstance takes no parameters and returns the sole instance. - newInstance--Like getInstance, except that newInstance guarantees that each instance returned is distinct from all others. - getType--Like getInstance, but used when the factory method is in a different class. Type indicates the type of object returned by the factory method. - newType--Like newInstance, but used when the factory method is in a different class. Type indicates the type of object returned by the factory method.
OrangeCLK对本书的所有笔记 · · · · · ·
说明 · · · · · ·