static 영역에 instance의 주소 할당.heap 영역에 데이터 할당public class EagerSingleton { private static EagerSingleton eager = new EagerSingleton(); private EagerSingleton() { // to maintain singleton pattern } public static EagerSingleton getInstance() { return eager; } }
public class LazySingleton { private static LazySingleton lazy; public static LazySingleton getInstance() { if (lazy == null) { // instanciation when method called lazy = new LazySingleton(); } return lazy; } }
- 만일
참조하는 변수가 null값으로 치환되면 해당 변수는 기존 가리키는 주소를 잃어 JVM은 runtime 시점에 NullPointException을 반환한다.
합의된 의견을 기준으로 진행할 것.집단의 목적성을 잃지 않도록 해야한다.