sirain
sirain

Reputation: 1168

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.

Upvotes: 27

Views: 17828

Answers (3)

Huseyin Aydin
Huseyin Aydin

Reputation: 838

Turn on option at:

Preferences > Editor > Inlay Hints > Types > Java > Implicit types.

enter image description here


You might also consider turn on all the options at:

Preferences > Editor > Inlay Hints > Parameter names > Java.

Upvotes: 54

Eugene
Eugene

Reputation: 856

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

Preferences/Editor/Inlay Hints

Upvotes: 9

ZhekaKozlov
ZhekaKozlov

Reputation: 39586

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

Settings -> Editor -> General -> Code Folding -> Replace 'var' with inferred type

Upvotes: 1

Related Questions