I have read that it is possible to implement Singleton
in Java using an Enum
such as:
public enum MySingleton {
INSTANCE;
}
Since Singleton Pattern is about having a private constructor and calling some method to control the instantiations (like some getInstance
), in Enums we already have an implicit private constructor.
I don't exactly know how the JVM or some container controls the instances of our Enums
, but it seems it already use an implicit Singleton Pattern
, the difference is we don't call a getInstance
, we just call the Enum.