20

Object + shortcutObject object = new Object();

Whether there is such shortcut?

Marcelo Glasberg
  • 29,013
  • 23
  • 109
  • 133
CarryFlag
  • 313
  • 2
  • 9

3 Answers3

20

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):

enter image description here

  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.

Marcelo Glasberg
  • 29,013
  • 23
  • 109
  • 133
14

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.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 3
    With all due respect to your generally good and thoughtful answers, this is probably just as bad as simply typing everything by hand. – Marcelo Glasberg Jun 29 '17 at 20:27
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).

enter image description here

Marcelo Glasberg
  • 29,013
  • 23
  • 109
  • 133