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 - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -