Home > Software design >  Bright green highlight in Android Studio
Bright green highlight in Android Studio

Time:10-09

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

CodePudding user response:

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.

  • Related