Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse - Declare variable based on return or get (Shortcut)

I'm not sure how to phrase this in a search, however I was curious if there's a shortcut in eclipse to allow us to declare a variable type based on what's after the equal.

For example:

firstname = User.getFirstName(); 

The minute you press enter, it would add "String" to the beginning of the line so it becomes:

String firstname = User.getFirstName();

Or even a shortcut key would suffice.

There are times when a class name might be long, or something like: Iterator<Entry<String, String>> which is long enough that a shortcut or auto add would be handy.

I'm not sure if this exists though.

Thanks guys.

like image 794
Multiplexor Avatar asked May 17 '13 17:05

Multiplexor


People also ask

What is the shortcut key for return type in Eclipse?

Now, if we need to step into a method, we use F5 to step into the method. Let's use F5 to step into the method from the previous example: Let's say we get into the setup() method and decide that's not where we need to be. We'll use the F7 shortcut to Step to the method return.

What is Ctrl Shift G in Eclipse?

Ctrl + Shift + G. Search for references in the workspace. Command + T. Ctrl + T. Shows type hierarchy of the current java class.

What does Ctrl d do in Eclipse?

General Editing – Eclipse Shortcuts CTRL D – Delete a line. CTRL <- or -> – Move one element left or right.

What does Ctrl S do in Eclipse?

1.1. Eclipse supports of course the typical shortcuts, e.g. Ctrl + S for saving, Ctrl + C for copying the selected text or file and Ctrl + V for pasting the element currently in the clipboard.


1 Answers

I usually just write the expression:

User.getFirstName()

Then highlight it and press Ctrl-2, then L for "assign to local variable".

like image 147
Jon Skeet Avatar answered Oct 18 '22 12:10

Jon Skeet