Created
September 29, 2019 08:58
-
-
Save IamLizu/94cbbf579dd5662483416d29ba0f7caa to your computer and use it in GitHub Desktop.
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 { | |
// holds instance of the singleton class | |
private static Singleton Instance; | |
public String text; | |
// private constructor | |
private Singleton (String text) { | |
this.text = text; | |
} | |
public static Singleton getInstance(String text) { | |
// checks if instance already created | |
if (Instance == null) { | |
// if not create an instance | |
Instance = new Singleton( text); | |
} | |
// return the created instance on all subsequent calls | |
return Instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment