Skip to content

Instantly share code, notes, and snippets.

@mikamboo
Last active December 17, 2015 23:58
Show Gist options
  • Save mikamboo/5693136 to your computer and use it in GitHub Desktop.
Save mikamboo/5693136 to your computer and use it in GitHub Desktop.
Java design pattern : Singleton
public class MySingleton {
private static MySingleton instance;
public String customVar;
public MySingleton()
{
if (instance == null)
{
// Create the instance
instance = new MySingleton();
}
}
public static MySingleton getInstance()
{
// Return the instance
return instance;
}
private MySingleton()
{
// Constructor hidden because this is a singleton
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment