When Scala evaluates the following multiple value assignment:
val a, b, c = UUID.randomUUID()
I expected a == b && b == c && c == a (A) or a == null && b == null && c == UUID (B)
However, the result is a != b && b != c && c != a (C), where each value is initialized to an individual UUID.
Why is this? Java behaves like (B). I believe that (C) is more convenient, however I have not been able to find an explanation in the language doc.
From the scala language reference section 4.1:
A value definition
val p1, ..., pn = eis a shorthand for the sequence of value definitionsval p1 = e; ...; val pn = e.
So your example is shorthand for:
val a = UUID.randomUUID()
val b = UUID.randomUUID()
val c = UUID.randomUUID()
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