¿Por qué un `val` dentro de un` objeto` no es automáticamente final?
¿Cuál es la razón deval
s no (?) siendo automáticamente final en objetos singleton? P.ej.
object NonFinal {
val a = 0
val b = 1
def test(i: Int) = (i: @annotation.switch) match {
case `a` => true
case `b` => false
}
}
resultados en:
<console>:12: error: could not emit switch for @switch annotated match
def test(i: Int) = (i: @annotation.switch) match {
^
Mientras
object Final {
final val a = 0
final val b = 1
def test(i: Int) = (i: @annotation.switch) match {
case `a` => true
case `b` => false
}
}
Compila sin advertencias, por lo que presumiblemente genera la tabla de coincidencia de patrones más rápida.
Tener que añadirfinal
Me parece puro ruido molesto. No es unobject
final per se, y por lo tanto también sus miembros?