Created
January 11, 2014 15:18
-
-
Save burhanaras/8372142 to your computer and use it in GitHub Desktop.
A simple implementation of Singleton pattern
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 class Singleton { | |
// Private constructor prevents instantiation from other classes | |
private Singleton() { } | |
/** | |
* SingletonHolder is loaded on the first execution of Singleton.getInstance() | |
* or the first access to SingletonHolder.INSTANCE, not before. | |
*/ | |
private static class SingletonHolder { | |
public static final Singleton INSTANCE = new Singleton(); | |
} | |
public static Singleton getInstance() { | |
return SingletonHolder.INSTANCE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment