I recently came to know that enum
is a more effcient way to implement singleton.
Singleton with enum
:
public enum Singleton{
INSTANCE;
public void doStuff(){
//......
}
public void doMoreStuff(){
//......
}
}
Singleton with class
:
public class Singleton{
private static final INSTANCE = new Singleton();
private Singleton(){}
public static Singleton getInstance(){
return INSTANCE;
}
public void doStuff(){
//......
}
public void doMoreStuff(){
//......
}
}
QUESTION: What are the possible advantages or disadvantages of using enum over class to implement the singleton ?