Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala declare multiple variables at the same row with the first character as upper-case

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"
like image 893
Johan S Avatar asked Dec 25 '22 01:12

Johan S


1 Answers

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.

like image 191
red1ynx Avatar answered May 23 '23 11:05

red1ynx