I have a Java Singleton class as :
public enum MyClass{
INSTANCE;
private MyClass(){
init();
}
private static void init(){
System.out.println("Singleton Class initiated");
}
}
When I try to instantiate the class by :
MyClass.INSTANCE;
I get an error that it is not a statement.
However, the following works, which is not ideal for production code:
System.out.println(MyClass.INSTANCE);
Is there a way to initiate the enum singleton class properly, without calling any other dummy API of the class?