skip to Main Content

I got this bright green highlight in some code I wrote:

screenshot

What is Android Studio trying to tell me?

There is no corresponding line in the scroll bar, no gutter icon, no tooltip and no special Alt+Enter action.

My color scheme is set to "Classic Light". Here’s what it looks like in Darcula:

screenshot

2

Answers


  1. This is a smart-cast that is occurring because you have asserted that event is not null. The event property of the message class must be immutable, meaning it is both a val and has no custom getter. (Or it might be a final field defined in a Java class.)

    Smart-casting only happens for local variables (not captured in an enclosure) and immutable properties (defined in the same module or marked private), because otherwise the compiler cannot guarantee that the value hasn’t changed since its type/nullability was last asserted.

    Login or Signup to reply.
  2. To disable this inspection, navigate to Editor -> Color Scheme -> Kotlin -> Smart-casts and uncheck background for each type

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search