For example, a class such as publicclassDiskUtil {privateDiskUtil () {} publicstaticFUNC () {}} usually provides some static functions to generate instances of this class, as long as this class has public attributes and methods, one party that gets the instance reference can still call it. One example is singleton. You can only call DiskU for external calls.
For example
Public class DiskUtil {private DiskUtil () {} public static FUNC (){}}
Such a class usually provides some static functions to generate the instance of this class. as long as this class has public attributes and methods, the party that gets the instance reference can still call it, one example is singleton.
The external call can only call the static function Func of DiskUtil, but not A a = new A (). The private constructor can only be called inside the function and cannot be instantiated outside the function, therefore, private constructors can prevent this class from being instantiated externally.
Common applications are Tool Type and Singleton mode.
Package test. reflect; public class Singleton {private static Singleton s = null; private Singleton () {} public static Singleton getInstance () {if (s = null) {synchronized (Singleton. class) {if (s = null) {s = new Singleton () ;}} return s ;}}