Enabling Type Hints in Android Studio
Android Studio offers type hints for Kotlin code. Basically, the IDE adds “fake” type declarations where your code does not have them, for places where the compiler is inferring the type:
The types with the gray backgrounds (e.g.,
PackageInstaller) are added by the
IDE. Other types (e.g.,
Uri) are really there in the typed-in code.
This can be handy for helping to ensure that your types are being inferred the way that you expect. They are also good for educational scenarios, such as conference presentations, to help make the implicit more explicit for people spending a limited amount of time in the code.
I got these by default with IntelliJ IDEA, and I wanted to enable them on Android Studio, particularly for tomorrow’s Android Summit workshop. This is possible, but you have to dig a bit in Settings to find them. Or, you can stumble across a helpful Stack Overflow answer.
In Settings > Editor > General > Appearance, you need to check “Show parameter name hints”:
Then, click the adjacent “Configure…” button and choose Kotlin from the “Language” drop-down in the resulting dialog:
The “Options” set of checkboxes are where you indicate the scenarios in which you want the type hints to show up. The large text field above those checkboxes are a blacklist, indicating situations where the IDE will skip the type hints, even if they otherwise would qualify based on your “Options” choices.
Nervous about how the newest version of Android affects your app? Consider subscribing, then asking questions in the office hours chats!