DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Java Singleton Template For Eclipse
This is a template for easily creating an implementation of the Singleton Pattern on Eclipse. Open Window->Preferences->Java->Editor->Templates click on New and insert the code below on the pattern text area; add a name (I suggest "singleton") - whenever you type this name and press Ctrl+Space the code will be inserted in your class - and you're good to go.
private static ${enclosing_type} instance;
private ${enclosing_type}(){}
public static ${enclosing_type} getInstance(){
if(null == instance){
instance = new ${enclosing_type}();
}
return instance;
}






Comments
Weei Jye Chay replied on Tue, 2007/02/13 - 10:39pm
Snippets Manager replied on Sun, 2007/02/11 - 5:06am
Snippets Manager replied on Sun, 2007/02/11 - 5:06am
Snippets Manager replied on Sun, 2007/02/11 - 5:06am
Marc Stock replied on Fri, 2007/03/02 - 6:59pm