Created
May 24, 2012 19:26
-
-
Save alexjlockwood/2783706 to your computer and use it in GitHub Desktop.
newInstance fragment instantiation #1
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
public static class Singleton { | |
private static final Singleton instance = null; | |
/** | |
* Make the class private to prevent direct instantiation. | |
* this forces clients to call newInstance(), which will | |
* ensure the class' Singleton property. | |
*/ | |
private Singleton() { } | |
public static Singleton newInstance() { | |
/** | |
* If instance is null, then instantiate the object | |
* by calling the default constructor (this is OK | |
* since we are calling it from within the class). | |
*/ | |
if (instance == null) { | |
instance = new Singleton(); | |
} | |
return instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment