1

Possible Duplicate:
What is the motivation for Scala assignment evaluating to Unit rather than the value assigned?

I was just wondering why an assignment in Scala returns Unit. It would be pretty useful if it returned the value assigned, so that we could chain assignments, like this:

val a = b = c = 9

I'm sure there must be a reason.

Community
  • 1
  • 1
opensas
  • 60,462
  • 79
  • 252
  • 386
  • 4
    Why would you ever want to assign three immutable vals to the same value? :) Anyway, `val a, b, c = 9` – Luigi Plinge Dec 11 '11 at 06:26
  • This is mostly a duplicate of [this](http://stackoverflow.com/questions/1998724/what-is-the-motivation-for-scala-assignment-evaluating-to-unit-rather-than-the-v) stack overflow question, but it is also useful to refer to [this](http://stackoverflow.com/questions/2442318/how-would-i-express-a-chained-assignment-in-scala) one with a limited workaround. – Tupshin Harper Dec 11 '11 at 06:11
  • +1 'cause you're right, that was a lousy example... – opensas Dec 12 '11 at 00:43

0 Answers0