what is singleton instances of the enumeration class in java?
Asked
Active
Viewed 102 times
0
-
2Context, please! Where did you hear about "singleton instances of the enumeration class"? – Jørn Schou-Rode Apr 21 '10 at 08:37
-
And some details [https://stackoverflow.com/questions/26285520/implementing-singleton-with-an-enum-in-java](https://stackoverflow.com/questions/26285520/implementing-singleton-with-an-enum-in-java) – Mykola Bova Nov 22 '17 at 17:51
1 Answers
1
Perhaps you're talking aobut using an enum to implement the singleton pattern?
public enum Singleton {
INSTANCE;
public void singletonMethod() { ... }
}
Since enums were added to Java, this is the best (shortest, most correct) way to implement singletons.

Michael Borgwardt
- 342,105
- 78
- 482
- 720