Variables with underline

I'm getting an underline in some variables on Android Studio (in this case on the 'position' variable). I think it's not an error because the application runs perfectly and the compiler passes everything ok. I'm wondering what does that mean?

enter image description here


Solution 1:

It could be a sign of "Reassigned parameter"

enter image description here

Solution 2:

I believe the underlined variables are representative of constants (final or effectively final), because in my experience I only see this decoration when I declare a final object for use inside an anonymous class. I can't seem to find it in the documentation, though.

Solution 3:

I've found the answer for this question here.

The decoration is a syntax highlighting preference. Take a look at File > Settings > Editor > Color Scheme > Java/Kotlin

In the case of Java, you can find this effect for example at Parameters > Implicit anonymous class parameter. It's the checkbox Effects.

enter image description here

The same with Kotlin at Properties and Variables > Var (mutable variable, parameter or property).

enter image description here

Solution 4:

This means the variable was declared outside the current method. For example, in this case, position is probably declared as a class member outside the new DialogInterface.OnClickListener(), in the class where you're implementing the onItemLongClick() method.

They are declared like this:

public class MyClass{
    private int position;

    // Other code...

}

Solution 5:

It may be because a immutable variable is subjected to modification. Like reassigning a String or trying to modify a final declared variable.

String buffer = "";
buffer = buffer + "new string";

Will underline the buffer, since string are of immutable Objects.