In the book "Programming in Scala", Third Edition, I saw an example that I could not understand. To understand it, I typed it into the scala interpreter:
scala> import scala.collection.mutable
import scala.collection.mutable
scala> val movieSet = mutable.Set("Hitch", "Poltergeist")
movieSet: scala.collection.mutable.Set[String] = Set(Poltergeist, Hitch)
scala> movieSet
res3: scala.collection.mutable.Set[String] = Set(Poltergeist, Hitch) <<< res3
scala> movieSet += "Shrek"
res4: movieSet.type = Set(Poltergeist, Shrek, Hitch) <<< res4
My understanding was when doing += on a mutable.Set, the Set should mutate in-place (i.e. the variable to which it is assigned should not change), but the reference changed from res3 to res4. Also, I understood "val movieSet" to create a value that cannot be changed. Shouldn't this cause "val movieSet" to remain with the res3 reference, and not change to res4?