Warum ist ein "Wert" in einem "Objekt" nicht automatisch endgültig?
Was ist der Grund fürval
Ist es nicht so, dass (?) in Singleton-Objekten automatisch endgültig ist? Z.B.
object NonFinal {
val a = 0
val b = 1
def test(i: Int) = (i: @annotation.switch) match {
case `a` => true
case `b` => false
}
}
Ergebnisse in:
<console>:12: error: could not emit switch for @switch annotated match
def test(i: Int) = (i: @annotation.switch) match {
^
Wohingegen
object Final {
final val a = 0
final val b = 1
def test(i: Int) = (i: @annotation.switch) match {
case `a` => true
case `b` => false
}
}
Kompiliert ohne Warnungen, generiert also vermutlich die schnellere Mustervergleichstabelle.
Hinzufügen müssenfinal
scheint mir pures nerviges geräusch zu sein. Ist nicht einobject
endgültig per se und damit auch seine mitglieder?