What's the best way to use shortcuts and autocomplete to create a new object in Intellij IDEA?

早过忘川 提交于 2019-12-28 05:41:06

问题


Object + shortcutObject 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):

  1. Go to Settings > Live Template.
  2. Then click the + to the right of the window, to add a new Live Template.
  3. Choose the abbreviation you want (Like n or newo). Description could be new Object .
  4. Add the template text: $Clazz$ $obj$ = new $Clazz$($END$);
  5. Click que Edit Variables button, and the fill in the Clazz and obj Expression and Default Value as shown in the picture above.
  6. Don't forget to click Define next to No applicable contexts, to define Java > 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!