When coding in Java (and Kotlin!) in Intellij, I usually extract variables/fields from the expression that they are being assigned. In other words, if I want to write the following code in Kotlin:
val name = getMyString()
Then I would write getMyString
, highlight it and extract the variable using a keyboard shortcut. Nice and simple.
But let's say I want the value type to be shown explicitly, meaning:
val name: String = getMyString()
If I use variable extraction, IntelliJ will offer me a checkbox, which I have to use my mouse to click, that will show the type. Another annoying option would be to set the variable name, then use Alt + Enter show the type explicitly.
Unlike previous questions (or JetBrains documentation), I do not want to have the type displayed by default. I just want to know if there is a keyboard shortcut to check the aforementioned checkbox, without disrupting the flow of writing the code.
Press Ctrl+Alt+V or from the main menu, select Refactor | Extract/Introduce | Variable. Select a name suggested in the popup or type your own and press Enter .
You can use the shortcut ctrl + shift + p to show inferred type of a variable when the cursor is on the variable in IntelliJ IDEA.
Add environment variablesFrom the main menu, select Run | Edit Configurations or choose Edit Configurations from the run/debug configurations selector on the toolbar. In the Run/Debug Configurations dialog, select a configuration you want to add the environment variables to.
After using the extract variable shortcut (Ctrl+Alt +V for Windows), you can use
Specify type explicitly
Declare with var
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