티스토리 뷰

일반적인 싱글톤 구현 코드~!

public class Singleton {
        // Private constructor prevents instantiation from other classes
        private Singleton() { }
  
        /**
        * SingletonHolder is loaded on the first execution of Singleton.getInstance()
        * or the first access to SingletonHolder.INSTANCE, not before.
        */
        private static class SingletonHolder {
                public static final Singleton instance = new Singleton();
        }
  
        public static Singleton getInstance() {
                return SingletonHolder.instance;
        }

}


** 빌 퍼그의 방법 The solution of Bill Pugh **


공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함