1

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

Is there a reason why assignments in scala evaluate to Unit?

var s:String = null

s = "hello"     // works
s += " world" 

(s = "hello") += " world" // dramatic problem

or is there something magic with the brackets?

Community
  • 1
  • 1
cybye
  • 1,171
  • 6
  • 13
  • Why not `s = "hello" + "world"`? Non-Unit assignments, such as `while((x = "foo") != true)` is hard to read. – om-nom-nom Jan 29 '13 at 17:47
  • I hoped for a simple answer ;) when I read the above Thread right, it's because non unit assignments do an overhead, that is normally not necessary. But scala has an intelligent compiler, that could handle it right anyway .. – cybye Jan 29 '13 at 18:16
  • read the comment of Odersky below the accepted answer... – kiritsuku Jan 29 '13 at 19:20

0 Answers0