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

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

android - MPAndroidChart - How to add Annotations or images to the chart -