Reputation: 149
How to see the type of variable in Android Studio when using Kotlin without type annotations.
Currently I'm trying to see it by giving the variable a type I know is incorrect and the IDE informs me with an error about the type it expected.
val variable = dont().know().type().ofThis()
To give example, I can press CTRL+P to see the signature of a function, is there a similar way to see the inferred type of a variable?
Upvotes: 9
Views: 7100
Reputation: 300
Hakan Karaduman, thank you for the question!
I see that you found the correct answer, however, the Android Studio IDE is changed its Settings
menu. Therefore, I decided to provide an updated location for the options that you requested.
In Android Studio 2021.1.1 Patch 1 the required list of options is located File
> Settings
> Editor
> Inlay Hints
> Kotlin
. That location consists of the following groups:
.. [v] Show parameter hints
...... Exclude list..
.. [v] Show hints for:
...... [v] Property types
...... [v] Local variable types
...... [v] Function return types
...... [v] Function parameter types
.. [v] Show hints for:
...... [v] Return expressions
...... [v] Implicit receivers and parameters
Upd #01 for Android Studio Flamingo | 2022.2.1 Patch 2
File
> Settings
> Editor
> Inlay Hints
Types
> Kotlin
:.. [v] Property types
.. [v] Local variable types
.. [v] Function return types
.. [v] Function parameter types
Values
> Kotlin
:.. [v] Ranges
Lambdas
> Kotlin
:.. [v] Return expressions
.. [v] Implicit receivers and parameters
Upvotes: 11
Reputation: 309
There is a menu item in the View menu: "Type Info"
Ctrl+Shift+P in Android Studio Win 3.5.3
Upvotes: 8
Reputation: 2300
You can enable Parameter name hints
for that
To do so, go to File
-> Settings
-> Editor
-> General
-> Appearance
and check the Show parameter name hints
. Be sure to click configure
button and at the Options
panel, check the required options, including show local variable type hints
:
Upvotes: 14