Skip to content

Instantly share code, notes, and snippets.

@igoticecream
Created January 31, 2017 18:53
Show Gist options
  • Save igoticecream/cf94b845eeb086b3e0e2946efd4bcbf8 to your computer and use it in GitHub Desktop.
Save igoticecream/cf94b845eeb086b3e0e2946efd4bcbf8 to your computer and use it in GitHub Desktop.
Doble check singleton implementation
@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