Skip to content

Instantly share code, notes, and snippets.

@chermehdi
Created November 8, 2016 14:18
Show Gist options
  • Save chermehdi/543701b2d0b841088e10d1363c6bef0e to your computer and use it in GitHub Desktop.
Save chermehdi/543701b2d0b841088e10d1363c6bef0e to your computer and use it in GitHub Desktop.
public class SimpleSingleton {
// this will hold the instance of the class
private static SimpleSingleton instance;
// this will be our constructor it's empty for no reason you can put
// anything necessary to instantiate your class
private SimpleSingleton() {}
//this is the static method to return the instance of the class
public static SimpleSingleton getInstance() {
//we only create the object when we need it
if(instance == null){
instance = new SimpleSingleton();
}
return instance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment