Created
August 22, 2015 01:44
-
-
Save patrykpoborca/b42bb8d1fb53a72e7c40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressWarnings("unchecked") // cast only happens when result comes from the factory | |
@Override | |
public T get() { | |
// double-check idiom from EJ2: Item 71 | |
Object result = instance; | |
if (result == UNINITIALIZED) { | |
synchronized (this) { | |
result = instance; | |
if (result == UNINITIALIZED) { | |
instance = result = factory.get(); | |
} | |
} | |
} | |
return (T) result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment