How to enable Inlay hints in Android studio

When working on Android project, you may encounter situations where you’ve declared several variables or functions with direct value.

For instance,

val number = 10
fun getLuckyNumber(from: Int) = Random.Default.nextInt(from)

Here, you are not explicitly stating the type of variable or function.

Although the Kotlin compiler is capable of inferring the type, you won’t always be able to do so. In such scenarios, determining the type requires analysis of the RHS of the code. However, there is a better approach.

Meet Inlay Hints

Inlay hints are special markers that appear in the editor and provide you with additional information about your code, like the names of the parameters that a called method expects. Other types of hints inform you about annotations, method parameters, usages, and so on.

To enable Inlay hints for types (or other feature)

1. Press Ctrl+Alt+S (or go to File -> Settings) to launch Settings window.

2. Go to Editor -> Inlay Hints -> Kotlin (or Java)

3. Check every box under Types.

4. You’ll find a nice little type information next to a variable/function in editor.
Share with your friends

Leave a Reply

Your email address will not be published. Required fields are marked *