This is a follow up question after reading answers to this question. Most of people so keen on recommending single element enums
over singleton class
implementations. For instance:
Singleton with enum:
public enum Singleton{
INSTANCE;
public void doStuff(){
//......
}
public void doMoreStuff(){
//......
}
}
According to Java Docs; An enum type is a special data type that enables for a variable to be a set of predefined constants.
My Question: Pardon me if this is a stupid question. As singletons are capable of maintaining global states for the application, When implementing singletons in with the single element enums
, how can you maintain different states with your singleton?
For example If I want my Singleton to keep followings;
public myStringField="";
public int myIntField=0;
How can I do it with single element enums
?