I used to think that private val
and private final val
are same, until I saw section 4.1 in Scala Reference:
A constant valu
I think the confusion here arises from conflating immutability with the semantics of final. val
s can be overridden in child classes and therefore can't be treated as final unless marked as such explicitly.
@Brian The REPL provides class scope at the line level. See:
scala> $iw.getClass.getPackage
res0: Package = package $line3
scala> private val x = 5
:5: error: value x cannot be accessed in object $iw
lazy val $result = `x`
scala> private val x = 5; println(x);
5