开发者

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 Obj开发者_开发技巧ect();

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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜