Scala Surprises for the Java Eyes
As you start to appreciate Scala’s design elegance and conciseness, you should be aware of some nuances—for example, Scala differs semantically from Java in the way it handles assignment, equality check, and return from functions. Since the way these are handled is a significant departure from what we’re used to in Java, it’s easy to make mistakes. Take the time to learn these to avoid surprises.
Result of Assignment
In Java, the result of the assignment operation, like a = b, is the value of a, so multiple assignments like x = a = b; can appear in series, but not so in Scala. The result of assignment operation in Scala is a Unit—a rough equivalent of Void. As a consequence, assigning that result to another ...