x = y =1 in Scala?
return-type, return-value, scala, variable-assignment
Solution
In fact, `x` is `Unit` in this case:
var y = 2
var x = y = 1
can be read as:
var y = 2
var x = (y = 1)
and finally:
var x: Unit = ()
Problem
While going through the book Scala for the Impatient, I came across this question: Come up with one situation where the assignment x = y = 1 is valid in Scala. (Hint: Pick a suitable type for x.) I am not sure what exactly the author means by this question. The assignment doesn't return a value, so something like `var x = y = 1` should return Unit() as the value of x. Can somebody point out what might I be missing here? Thanks