It's just like
var a = 1 { var a = 2 println(a) } println(a)
which prints
2 1
It doesn't matter if they are var or val s. In Scala, you are allowed to obscure variables from the outer scope, but this can lead to some confusion when you exscused should use the val keyword, that is, for understanding, anonymous functions, and pattern matching.
source share