What is meant by "immutable data"?

val does not mean immutable, it means that variable is not variable, or on other words it could not be reassigned to new value. But since the value itself is reference, its content could be changed without modifying the reference.

True immutability means that object could not be mutated in any way and always remains the same. For now JVM does not implement this on the language level, so the only way to ensure some object is immutable is to check that all objects which are referenced inside are immutable themselves, which is not so simple and seldom could not be checked in compile time.

I understand, that Kotlin team is working on solutions for that, but it is not that simple.

1 Like