Created
January 31, 2017 18:53
-
-
Save igoticecream/cf94b845eeb086b3e0e2946efd4bcbf8 to your computer and use it in GitHub Desktop.
Doble check singleton implementation
This file contains 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({"unused", "FieldCanBeLocal", "WeakerAccess"}) | |
public final class Singleton { | |
private static volatile Singleton ourInstance = null; | |
public static Singleton getInstance() { | |
if (ourInstance == null) { | |
synchronized (Singleton.class) { | |
if (ourInstance == null) { | |
ourInstance = new Singleton(); | |
} | |
} | |
} | |
return ourInstance; | |
} | |
private Singleton() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment