@Test(expected = IllegalProgramException.class) public void testInvokeConstructor() { B.getInstance(); }
@SuppressWarnings("unchecked") public static <T extends Singleton> T getInstance(Class<T> clazz) { Singleton singleton; Lock lock; (lock = GLOBAL_LOCK.readLock()).lock(); try { singleton = CACHE.get(clazz); } finally { lock.unlock(); } if (singleton == null) { (lock = GLOBAL_LOCK.writeLock()).lock(); try { singleton = (T)CACHE.get(clazz); if (singleton == null) { singleton = (T)createInstance(clazz); CACHE.put(clazz, singleton); } } finally { lock.unlock(); } } return (T)singleton; }
Singleton { @SuppressWarnings("unchecked") public static <T extends Singleton> T getInstance(Class<T> clazz) { Singleton singleton; Lock lock; (lock = GLOBAL_LOCK.readLock()).lock(); try { singleton = CACHE.get(clazz); } finally { lock.unlock(); } if (singleton == null) { (lock = GLOBAL_LOCK.writeLock()).lock(); try { singleton = (T)CACHE.get(clazz); if (singleton == null) { singleton = (T)createInstance(clazz); CACHE.put(clazz, singleton); } } finally { lock.unlock(); } } return (T)singleton; } }
Singleton { @SuppressWarnings("unchecked") public static <T extends Singleton> T getInstance(Class<T> clazz) { Singleton singleton; Lock lock; (lock = GLOBAL_LOCK.readLock()).lock(); try { singleton = CACHE.get(clazz); } finally { lock.unlock(); } if (singleton == null) { (lock = GLOBAL_LOCK.writeLock()).lock(); try { singleton = (T)CACHE.get(clazz); if (singleton == null) { singleton = (T)createInstance(clazz); CACHE.put(clazz, singleton); } } finally { lock.unlock(); } } return (T)singleton; } protected  Singleton(); }
Singleton { @SuppressWarnings("unchecked") public static <T extends Singleton> T getInstance(Class<T> clazz) { Singleton singleton; Lock lock; (lock = GLOBAL_LOCK.readLock()).lock(); try { singleton = CACHE.get(clazz); } finally { lock.unlock(); } if (singleton == null) { (lock = GLOBAL_LOCK.writeLock()).lock(); try { singleton = (T)CACHE.get(clazz); if (singleton == null) { singleton = (T)createInstance(clazz); CACHE.put(clazz, singleton); } } finally { lock.unlock(); } } return (T)singleton; } protected  Singleton(); @SuppressWarnings("unchecked") static T getInstance(Class<T> clazz); }
Singleton { @SuppressWarnings("unchecked") public static <T extends Singleton> T getInstance(Class<T> clazz) { Singleton singleton; Lock lock; (lock = GLOBAL_LOCK.readLock()).lock(); try { singleton = CACHE.get(clazz); } finally { lock.unlock(); } if (singleton == null) { (lock = GLOBAL_LOCK.writeLock()).lock(); try { singleton = (T)CACHE.get(clazz); if (singleton == null) { singleton = (T)createInstance(clazz); CACHE.put(clazz, singleton); } } finally { lock.unlock(); } } return (T)singleton; } protected  Singleton(); @SuppressWarnings("unchecked") static T getInstance(Class<T> clazz);  }