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


This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under
CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

Issue

for example I have this code

categoryCT.getInsertedItems();

and I want shortcut to generate code like this

List<Category> insertedItems=   categoryCT.getInsertedItems();


Solution

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”

Answered By – Aaron Digulla

people found this article helpful. What about you?