java - How to stop creating instance of Singleton -
i have singleton class this:
class singleton { static class singletonholder { static final singleton instance = new singleton(); } public static singleton getinstance() { return singletonholder.instance; } }
can call other class:
singleton dummy = new singleton();
if yes how can disable it? if not, why cannot i?
sure. make constructor private avoid that: add private singleton() {}
prevent default constructor being public.
Comments
Post a Comment