tags:

views:

83

answers:

4

There´s any eclipse shortcut to stance a new object ? For example. I would like to type:

Object zzz = 

and it would complete for me this way:

Object zzz = new Object();

with void parameter of course. I will wait answers.. thank you people.

+1  A: 

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.

Nailuj
Yes it worked friend but in my eclipse Ganymede it doesn´t put the () in the end.. its not very usefull I think.
Felipe
Well, in Galileo it also gives you the parenthesis, so I guess it is time for you to upgrade ;) But seriously, how much work is it really to manually add ()..?
Nailuj
yes you right.. just a silly detail.Thank you
Felipe
A: 

Eclipse ships with a default template new. To use it, type "new" then Ctrl-Space (or your autocomplete key sequence) and select "new - create new object." You will then be prompted in-line to fill in the type, variable name and arguments. Use tab to move to the next field.

Mark Peters
Thank you for your answer.
Felipe
+2  A: 

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}();
Eyal Schneider
Thank you, it´s very usefull. I didn´t know before.
Felipe
A: 

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.

Angelo Genovese