'How to see the type of variable within Android Studio IDE

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?



Solution 1:[1]

You can enable Parameter name hints for that

Example of type hints

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:

Enable type hints Type hints configuration

Solution 2:[2]

There is a menu item in the View menu: "Type Info"

Ctrl+Shift+P in Android Studio Win 3.5.3

Solution 3:[3]

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:

  • Parameter hints:

.. [v] Show parameter hints
...... Exclude list..

  • Types:

.. [v] Show hints for:
...... [v] Property types
...... [v] Local variable types
...... [v] Function return types
...... [v] Function parameter types

  • Lambdas:

.. [v] Show hints for:
...... [v] Return expressions
...... [v] Implicit receivers and parameters

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Paul Roub
Solution 3 Oleksandr.D