An enum
type is a special type of class
.
Your enum
will actually be compiled to something like
public final class MySingleton {
public final static MySingleton INSTANCE = new MySingleton();
private MySingleton(){}
}
When your code first accesses INSTANCE
, the class MySingleton
will be loaded and initialized by the JVM. This process initializes the static
field above once (lazily).