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

3

25

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.

Halm answered 26/6, 2019 at 15:0 Comment(2)
It's already supported, see youtrack.jetbrains.com/issue/IDEA-194935 .Desmid
Not quite the same feature -- what they have implemented is showing the hints when you fold the var declaration line.Chary
C
47

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.

Carping answered 25/7, 2022 at 8:58 Comment(0)
L
9

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

Preferences/Editor/Inlay Hints

Lucillelucina answered 2/2, 2021 at 18:40 Comment(0)
D
1

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

Settings -> Editor -> General -> Code Folding -> Replace 'var' with inferred type
Despairing answered 8/11, 2019 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.