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

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -