Java Singleton Pattern

  • + 4 comments

    Guys, why did my solution with static holder class had some weird assertion? It's definetely the best singleton implementation for Java:

    class Singleton {
        private Singleton() {}
    
        public static Singleton getInstance() {
            return SingletonHolder.INSTANCE;
        }
    
        private static class SingletonHolder {
            public static final Singleton INSTANCE = new Singleton();
        }
    }