What is meant by "immutable data"?

Copying the description which was used in the survey:

Kotlin has immutable variables (val’s), but no language mechanisms that would guarantee true “deep” immutability of the state. If a val references a mutable object, it’s contents can be modified:

val myVal = arrayListOf(1)
myVal.add(2) // mutation

Read-only interfaces for collections help somewhat, but we’d need something like readonly/immutable modifier for all types to ensure true immutability. Syntax is purely provisional:

class Foo(var v: Int)

immutable class Bar(val foo: Foo) // error: mutable reference from immutable class
1 Like