Por que um `val` dentro de um` objeto` não é automaticamente final?
Qual é a razão paraval
s não (?) sendo automaticamente final em objetos singleton? Por exemplo.
object NonFinal {
val a = 0
val b = 1
def test(i: Int) = (i: @annotation.switch) match {
case `a` => true
case `b` => false
}
}
resulta em:
<console>:12: error: could not emit switch for @switch annotated match
def test(i: Int) = (i: @annotation.switch) match {
^
Enquanto que
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 sem avisos, então, presumivelmente, gera a tabela de correspondência de padrões mais rápida.
Ter que adicionarfinal
Parece puro ruído irritante para mim. Não é umobject
final per se, e assim também seus membros?