What is the eclipse java declaration shortcut?

Try the template 'new':

1) type new and then ctrl+space.

2) Choose the 'create new object' option

3) Insert the class name and parameters (if needed)

If you don't want the parameters, you can create a template yourself (preferences->java->editor->templates). Assign a unique name to it, and set the pattern to:

${type} ${name} = new ${type}();

If you type Object zzz = new and then <crtrl>+<space> that brings up intellisense, and you can just hit <enter> and you'll get the first available constructor.


An alternative is to write new Object() and then use the "Extract Local Variable" Refactoring (Alt + Shift + L), in cases where I need to pass in parameters to the constructor I find this works well.

Tags:

Java

Eclipse