I'm trying to declare variables through tuple-assignment, such as:
val (hi, bye) = ("hi", "bye")
And obviously this is fine. However when having the first character as upper-case, the compiler explodes and complains about these variables not being already defined.
val (Hi, Bye) = ("hi", "bye")
Why doesn't this work? I'm running Scala 2.11.
By the way this works (as expected):
val Hi = "hi"
val Bye = "bye"
From here:
The tuple on the left-hand side is a pattern; names starting with capital letters are treated as constants when occurring inside a pattern. These constants must exist as values in the context. You find the exact semantics in the Scala spec under pattern matching.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With