Skip to content

Instantly share code, notes, and snippets.

View IamLizu's full-sized avatar
:octocat:

S M Mahmudul Hasan IamLizu

:octocat:
View GitHub Profile
public static synchronized Singleton getInstance() {
// checks if instance already created
if (Instance == null) {
// if not create an instance
Instance = new Singleton();
}
// return the created instance on all subsequent calls
return Instance;
}
public class Singleton {
// holds created instance of the singleton class
private static Singleton Instance = new Singleton();
// private constructor
private Singleton () {}
public static Singleton getInstance() {
// return the created instance on all subsequent calls
return Instance;
public class Singleton {
private volatile static Singleton Instance();
private Singleton () {}
public static Singleton getInstance() {
if (Instance == null) {
synchronized (Singleton.class) {
if (Instance == null) {