Created
November 8, 2016 14:18
-
-
Save chermehdi/543701b2d0b841088e10d1363c6bef0e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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