Closed
Description
When we declare a final var
and then assign a new value we get a NoSuchFieldError
.
object Test {
def main(args: Array[String]): Unit = {
NoStackTrace2._noSuppression = true
}
}
object NoStackTrace2 {
final var _noSuppression: Boolean = false
}
java.lang.NoSuchFieldError: _noSuppression$$local
at NoStackTrace2$._noSuppression_$eq(test.scala:8)
at Test$.main(test.scala:3)
at Test.main(test.scala)
In the byte code we get:
public final class NoStackTrace2$ {
...
public boolean _noSuppression() {
return false;
}
public void _noSuppression_$eq(boolean x$1) {
this._noSuppression$$local = x$1;
}
}
Which makes me think that we are handling final var
as a final val
at some point because the false
initial value was inlined in the getter and the field is not there.