The reason you read says that this is the easiest way to make lazy singles, because it should just work. Try the following:
public class LazyEnumTest { public static void main(String[] args) throws InterruptedException { System.out.println("Sleeping for 5 seconds..."); Thread.sleep(5000); System.out.println("Accessing enum..."); LazySingleton lazy = LazySingleton.INSTANCE; System.out.println("Done."); } } enum LazySingleton { INSTANCE; static { System.out.println("Static Initializer"); } }
Here I get the output in the console:
$ java LazyEnumTest Sleeping for 5 seconds... Accessing enum... Static Initializer Done.
source share