Felipe
Felipe

Reputation: 75

What is the eclipse java declaration shortcut?

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.

Upvotes: 7

Views: 5262

Answers (5)

ZhaoGang
ZhaoGang

Reputation: 4915

The shortcut should be Ctrl+Space as other answers mentioned.


Another walk around for people who has it has assigned to other applications and don't want to(or don't know how to) modify it:

Change the default in Auto activation triggers for Java to ._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ(note the white space after Z) for content assist in Preferences.

It may sometimes be annoying though, since it may pop up too frequently.


PS: the new template and the content assist should be two different concepts.

Upvotes: 0

Angelo Genovese
Angelo Genovese

Reputation: 3398

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.

Upvotes: 3

Eyal Schneider
Eyal Schneider

Reputation: 22446

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}();

Upvotes: 11

Mark Peters
Mark Peters

Reputation: 81104

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.

Upvotes: 0

Julian
Julian

Reputation: 20324

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.

Upvotes: 4

Related Questions