Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate return value type and variable assignment in Eclipse java editor?

If I have a statement like this " EntitiesProvider.getEntities();

Any idea how to "generate" the assignment to variable of return Type ?

so that this would be generated Map<String, Entity> hashMap =

this is the result :

Map<String, Entity> hashMap = EntitiesProvider.getEntities();

It is similar to ctrl + 1 and Change type, if it returns different Type that you already have there.

I find myself doing myself manually very often...

like image 257
lisak Avatar asked Aug 17 '11 14:08

lisak


People also ask

How to get return type in Eclipse?

Ctrl+2, L is one option, and the other is Alt+Shift+L when the desired statement is selected. The popup will appear allowing to set variable name & few additional options (e.g., "Replace occurrences of the selected expression with references to the local variable").

How to assign local variable in Eclipse?

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

What is the shortcut key for return type in selenium?

We can type Enter/Return key in Selenium. We shall use the sendKeys method and pass Keys. ENTER as an argument to the method.

How do I find variables in Eclipse?

Variables/Expression view – Shows the declared variables and their values. Press Ctrl+Shift+d or Ctrl+Shift+i on a selected variable or expression to show its value. You can also add a permanent watch on an expression/variable that will then be shown in the Expressions view when debugging is on.


1 Answers

Ctrl+2, L is one option, and the other is Alt+Shift+L when the desired statement is selected. The popup will appear allowing to set variable name & few additional options (e.g., "Replace occurrences of the selected expression with references to the local variable").

I prefer Alt+Shift+L because it allows marking specific part of the line for variable extraction.

.. and here's a simple example:

..
new FileInputStream(new File("test.txt"));
..

You can select the whole line to assign it to FileInputStream variable, or you can 'extract' new File("test.txt"), or even String expression "test.txt".

P.S. Sometimes I wish it would be able to let me choose supertype from combo box in a pop-up, e.g. InputStream in this specific example.

like image 117
Art Licis Avatar answered Sep 18 '22 11:09

Art Licis