Created
May 30, 2009 04:00
-
-
Save nandub/120361 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
//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(); |
10 yers ago,this simple exemple helped me.
thanks!
you very welcome. Useful little snippet :)
@nandub Thanks man.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
10 yers ago,this simple exemple helped me.
thanks!