问题
Object
+ shortcut
➜ Object object = new Object();
Whether there is such shortcut?
回答1:
new Obj
, Tab to complete to new Object()
, Ctrl+Alt+V (Refactor
| Introduce Variable):
Object o = new Object();
Change name if needed and press Enter to confirm.
For the more convenient solution utilizing the live templates feature please check the answer below from @MarcG.
回答2:
As of 2017, improving on @aleksander's answer, I believe the best way to create a new object as efficiently as possible in Intellij IDEA, is this (click to enlarge):
- Go to
Settings > Live Template
. - Then click the
+
to the right of the window, to add a new Live Template. - Choose the abbreviation you want (Like
n
ornewo
). Description could benew Object
. - Add the template text:
$Clazz$ $obj$ = new $Clazz$($END$);
- Click que
Edit Variables
button, and the fill in theClazz
andobj
Expression and Default Value as shown in the picture above. - Don't forget to click
Define
next toNo applicable contexts
, to defineJava > Statement
as the context.
Now test it: Go to the editor, type n
and then the TAB
key.
回答3:
You can define your own Live Template. Press Crtl+Alt+Shift+S (go to Settings), then go to tab Live Templates and write down something similar to below and you will have new shortcut (newo+tab).
来源:https://stackoverflow.com/questions/11891641/whats-the-best-way-to-use-shortcuts-and-autocomplete-to-create-a-new-object-in