Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can IntelliJ show type hints for automatically inferred local variables in Java 10?

IntelliJ shows type hints for local variables in Kotlin as shown here:

Type hints in Kotlin

This makes it easy to see the type of variables even if their types are inferred. Java 10 introduces type inference for Java with the var keyword. However, IntelliJ does not show any type hints by default:

enter image description here

After searching the internet for a bit, I was unable to find any information on how to enable type hints for local variables for Java. Is this even possible currently?

I use IntelliJ Community Edition 2019.1 on Windows 10.

like image 209
sirain Avatar asked Jun 26 '19 15:06

sirain


People also ask

How do I enable hints in Intellij?

View parameter hints in the editorOpen the Settings/Preferences dialog ( Ctrl+Alt+S ) and go to Editor | Inlay Hints | <required language>. Select Parameter hints from the list, make sure the Show parameter hints checkbox is selected, and then specify the context where you want parameter hints shown.

How do I find variables in Intellij?

To navigate to the code where the variable is declared, right-click a variable and select Jump to Source F4 . To navigate to the class declaration of the variable type, right-click a variable and select Jump to Type Source F4 .


3 Answers

IDEA doesn’t have this feature yet. You can raise a feature request at https://youtrack.jetbrains.com/issues/IDEA.

like image 157
Behrang Avatar answered Nov 04 '22 04:11

Behrang


In the latest version of IntelliJ (2020.3) these are called "Inlay Hints"

Preferences/Editor/Inlay Hints

like image 21
Eugene Avatar answered Nov 04 '22 06:11

Eugene


The closest feature in Java is Replace 'var' with inferred type:

Settings -> Editor -> General -> Code Folding -> Replace 'var' with inferred type
like image 45
ZhekaKozlov Avatar answered Nov 04 '22 06:11

ZhekaKozlov