Core concept

val x = 42       // immutable
var y = 0        // mutable
Advertisement

How it works

var still allows internal mutation of referenced object. Immutable data structures paired with val for full immutability.

Advertisement

Trade-offs + gotchas

Nearly always val. var only when clearly needed (perf, local mutable accumulators).