Overcomplicated singleton
https://github.com/RefactoringGuru/design-patterns-java/blob/760142524cef5697bb0296f6400340380a962357/src/refactoring_guru/singleton/example/thread_safe/Singleton.java#L43-L52
Why do you prefer this overcomplicated code instead of concise, simple, thread-safe, and lazy enough
private static final Singleton instance = new Singleton();
?
private static final Singleton instance = new Singleton();
is actually the eager initialization which will cause a slowdown in your application during startup.
The alternatives that can be used in place of the above mentioned double-check synchronized lock is Bill-Pugh's Singleton & Enums, both of these are thread-safe and allows lazy initialization.
will cause a slowdown
This is wrong because classes are loaded lazily, according to JVM spec. Enums are genereted in exactly same way: public static constants are assigned during static initialization.
@Miha-x64 what spec do you reference exactly?
@roeniss https://docs.oracle.com/javase/specs/jls/se16/html/jls-12.html#jls-12.4.1