Skip to content

Instantly share code, notes, and snippets.

@burhanaras
Created January 11, 2014 15:18
Show Gist options
  • Save burhanaras/8372142 to your computer and use it in GitHub Desktop.
Save burhanaras/8372142 to your computer and use it in GitHub Desktop.
A simple implementation of Singleton pattern
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