Generate local variable to receive the return value of a method eclipse

Eclipse can't help you with the variable name but you can write:

insertedItems = categoryCT.getInsertedItems();

This will give you a compile error.

If you press Ctrl+1 anywhere in this line, Eclipse will offer "Create local variable 'insertedItems'"

Fewest keystrokes to get the desired result:

  • catCTCtrl+Space -> categoryCT
  • .getIICtrl+Space -> categoryCT.getInsertedItems()
  • ;
  • Shift+Alt+Left to select the whole method invocation
  • Ctrl+1 + select "Create new local variable"

I'd add for windows users:

Press ctrl+2 for the available options.

For ex. ctrl+2+L will assign your statement to a local variable.


The shortcut that works on my Mac is 2 + l (lowercase L key)

Steps:

  • Write the variable, Ex: categoryCT.getInsertedItems();;
  • Select the entire variable definition;
  • Press 2, leave the press and then press l(lowercase L key);

This will create the line List<Category> insertedItems= categoryCT.getInsertedItems();.

Tags:

Java

Eclipse