Public class Singleton{
//private static ref
private Static Singleton uniqueInstance;
//private constructor
private Singleton(){
}
public static Singleton getInstance{
if(uniqueInstance==null){
uniqueInstance= new Singleton();
}
return uniqueInstance;
}
}
The above class is my current implementation of the traditional use of singleton. How would I implement the enum version of singleton on this class? And what are its benefits over the traditional?
I.e. how does this work:
public enum Foo {
INSTANCE;
}