3 ms·
The article talks about immutable objects vs read-only objects. Final and Val means read only, the reference is immutable, not the object. For class variables V
by jorgemf 9y ago
The article talks about immutable objects vs read-only objects. Final and Val means read only, the reference is immutable, not the object. For class variables Val and final are almost exactly the same.
- vbezhenar 9y agoval reference is not immutable. Your val can return new reference every time it's called: val x: String get() = (i++).toString() And JVM just don't have any notion about immutable objects, so Kotlin, obviously, don't have them either. You can return some ImmutableList and I'll change it using reflection and laugh at you. Immutability in Java is about conventions and trust.
- jorgemf 9y agoI said Val means read only, not immutable. I never said java have immutability (only for primitive values)