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

后端 未结 3 1870
暗喜
暗喜 2020-12-05 10:54

Object + shortcutObject object = new Object();

Whether there is such shortcut?

3条回答
  •  余生分开走
    2020-12-05 11:49

    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.

提交回复
热议问题