effective javaSummary

1. A static factory method should be used instead of new an object.

Reason: Factory methods have specific names that are easier to read by client code.

          For some non-mutable objects, you can reuse objects through factory methods, and you can directly use == to determine whether the objects are equal

          Can return a subtype of the original return type

2. Private constructor guarantees a singleton (singleton)

Use public static final fields: simple and convenient, better performance

Use static method: can add some logic


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324728153&siteId=291194637