AndreKR
AndreKR

Reputation: 33678

Bright green highlight in Android Studio

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

Upvotes: 1

Views: 1468

Answers (2)

seekingStillness
seekingStillness

Reputation: 5093

To disable this inspection, navigate to Editor -> Color Scheme -> Kotlin -> Smart-casts and uncheck background for each type

enter image description here

Upvotes: 1

Tenfour04
Tenfour04

Reputation: 93609

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.

Upvotes: 3

Related Questions