Quantcast
Channel: default
Viewing all articles
Browse latest Browse all 10

Scala: Understanding mutable variables with immutable collections

$
0
0

Scala: Understanding mutable variables with immutable collections

This is an excerpt from the Scala Cookbook (partially re-worded for the internet). This is Recipe 10.6, “Understanding Mutable Variables with Immutable Collections.”

Problem

You may have seen that mixing a mutable variable (var) with an immutable collection causes surprising behavior. For instance, when you create an immutable Vector as a var, it appears you can somehow add new elements to it:


Viewing all articles
Browse latest Browse all 10

Trending Articles