This could be a simple one and there may be duplicates of this type of question, but I can't find the answer anywhere. I want to complete the type of the variable by inferring the method's return type in Java. For example,
users = userService.findAllUsers()//This method returns List<User> objects
Now I want to place cursor on users variable and initialise it inline by selecting a "shortcut" key and Intellij will complete the above statement like below.
List<User> users = userService.findAllUsers()//This method returns List<User> objects
How is this possible? Do I need to add a custom shortcut to keymap or is there one already available like in Eclipse? Finally I would like to know the shortcut for Mac OSX if there is one available.
I have found the IntelliJ Postfix Code Completion very useful and powerful.
In your case you could do like this:
Create your expression without any variable
Start typing .var
at the end of the expression and you will get a context menu with var
as a selectable item. Press Enter and a new variable will be created for you:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With