28 Immutable collections with var
One thing to note is the difference between the +=
, +==
, -=
, -==
etc functions regarding mutalbe and immutable collections.
- For immutable collections - they are not methods of the collection (since it’s not modifiable) but if used on an immutable collection declared with
var
instead ofval
then the Scala compier expands them tovariable = variable op param
. (seel on the left for an example) - For mutable collections - they are actually methods on the collection, and they modify the collection when used.