I have a variable that I want to declare like:
val foo : Baz
for (s <- barList) {
if s.tag == "java"
foo = s
}
Once foo is assigned a value, foo cannot be reassigned. From this perspective foo is of type val and not var. But above is not valid scala code as scala forces to assign a value at the declaration time. Even if I use var, scala forces me to assign a value. Is there a better solution? The reason I would like val is because it results in better performance and val semantics fits in above scenario.
I’d do something like this: