Search code examples
javaintellij-ideahotkeys

How to infer and complete variable type with Intellij IDEA


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.


Solution

  • For Windows

    Use Ctrl+Alt+V to create variable (as it says here)

    For Mac OS

    Use ++V