Are you writing your Java classes as Singletons quite often? Use this Eclipse template and make any class a singleton in two seconds:
Setup
Go to Window -> Preferences -> Java -> Editor -> Templates. Create New:
Code for copy paste:private static final ${enclosing_type} instance = new ${enclosing_type}();
private ${enclosing_type}() {}
public static ${enclosing_type} getInstance() {
return instance;
}
Action
Type "single" or "singleton", hit Content Assist shortcut key (ctrl+space by default), then enter:
And there you go - a singleton in two seconds (actual time may vary on your typing and CPU speed).
You may want to use a different Singleton implementation. Check out Java Singleton: The Proper Way for a good example.
Error'd: Three Little Nyms
2 days ago
eclipse templates makes a lot of things easy :)
ReplyDeleteThank you for the tip. Very helpful.
ReplyDeleteLove it.
ReplyDeleteJust googled for something like this and this blog came nearly on top.