Effective java study notes 3: private constructor function to strengthen the ability of the examples of
Abstract: Effective java study notes 3: private constructor function to strengthen the ability of the examples of
: Sometimes we will compile some contained only static and passive methods of domain category. Such as the operation of the original type and the array together types of methods: java.lang.Math, java.util.Arrays .. or to operate in a particular on the subject of the interface methods together, for example, java.util.Collections.
This time, not to try to create a category to make abstract non examples, because abstract class can be inherited by the end of the examples. Should also not give structure to function, because even if this had not constructor function will be given a jvm The default constructor function.
Therefore, a show can be given a private constructor function to ensure that an instantiation.
Example:
/ / Noninstantiable utility class - page 12
(Public class UtilityClass
/ / Suppress default constructor for noninstantiability
Private UtilityClass () (
/ / This constructor will never be invoked
)
/ / … / / Remainder omitted
)
Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss, spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd
↑ Back






