Skip to content

Instantly share code, notes, and snippets.

@deskid
Created August 31, 2015 01:29
Show Gist options
  • Save deskid/8e50a2d648e00814639d to your computer and use it in GitHub Desktop.
Save deskid/8e50a2d648e00814639d to your computer and use it in GitHub Desktop.
what Singleton should be
abstract class Singleton<T> {
private T mInstance;
protected abstract T create();
public final T get() {
synchronized (this) {
if (mInstance == null) {
mInstance = create();
}
return mInstance;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment