Created
August 31, 2015 01:29
-
-
Save deskid/8e50a2d648e00814639d to your computer and use it in GitHub Desktop.
what Singleton should be
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
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