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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access