Reputation: 2530
To instantiate the variables can do so:
scala> var (a, b, c) = (0, 0, 23)
a: Int = 0
b: Int = 0
c: Int = 23
but if I wanted to do such a thing?
scala> a = b = c
<console>:10: error: type mismatch;
found : Unit
required: Int
a = b = c
^
how can I do?
Thanks
Upvotes: 1
Views: 305
Reputation:
You can't do a = b = c
because a
has already been defined as a Int var
, and with the a = b = c
statement you are giving a
a Unit
, 'b = c'.
When you assign a value to a variable in Scala you don't get as a result the value assigned.
In other languages b = c
would be evaluated to 23, the value of c. In Scala b = c
is just a Unit
, writing a = b = c
is exactly like writing a = (b = c)
, hence the error.
Upvotes: 2