Skip to content

Instantly share code, notes, and snippets.

@nandub
Created May 30, 2009 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nandub/120361 to your computer and use it in GitHub Desktop.
Save nandub/120361 to your computer and use it in GitHub Desktop.
//http://viralpatel.net/blogs/2009/01/java-singleton-design-pattern-tutorial-example-singleton-j2ee-design-pattern.html
public class SimpleSingleton {
private static SimpleSingleton singleInstance = new SimpleSingleton();
//Marking default constructor private
//to avoid direct instantiation.
private SimpleSingleton() {
}
//Get instance for class SimpleSingleton
public static SimpleSingleton getInstance() {
return singleInstance;
}
}
//or
public enum SimpleSingleton {
INSTANCE;
public void doSomething() {
}
}
//Call the method from Singleton:
SimpleSingleton.INSTANCE.doSomething();
@caiobraga98
Copy link

10 yers ago,this simple exemple helped me.
thanks!

@nandub
Copy link
Author

nandub commented Sep 15, 2020

10 yers ago,this simple exemple helped me.
thanks!

you very welcome. Useful little snippet :)

@Unidentified539
Copy link

@nandub Thanks man.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment