Reputation: 393
I'm trying Scala 2.9 (and I like it!) Consider the following:
scala> "hello" += " world"
<console>:8: error: value += is not a member of java.lang.String
"hello" += " world"
And now
scala> var h = "hello "
h: java.lang.String = "hello "
scala> h += "world"
scala> h
res24: java.lang.String = hello world
I would have thought that both string expressions in the first example would naturally evaluate in order to allow the operation. Is there a good reason for this behavior?
Cheers!
Upvotes: 2
Views: 186
Reputation: 23465
You can't modify a constant.
"hello"
is constant, h
isn't.
You're writing
"hello" = "hello" + " world"
which doesn't make a lot of sense.
Upvotes: 10