Item 4: Enforce noninstantiability with a private constructor

1.    Classes that are just a grouping of static methods and static fields can be used to group related methods on primitive values or arrays, in the manner of java.lang.Math or java.util.Arrays. They can also be used to group static methods, including factory methods for objects that implement a particular interface, in the manner of java.util.Collections. Lastly, they can be used to group methods on a final class, instead of extending the class. Such utility classes were not designed to be instantiated: an instance would be nonsensical.

 

2.    A class can be made non-instantiable by including a private constructor.

 

3.    As a side effect, this idiom also prevents the class from being subclassed.

你可能感兴趣的:(Effective Java)