Re:Kotlin 1.2.20 released
by lmm on Wednesday January 17, 2018 @11:13AM
(#16169047)
There are no built-in immutable collection types; what Kotlin calls "immutable" is closer to C "const" i.e. it could be a view onto a list that's mutated elsewhere. This means you can't safely write a method that requires an immutable list; if you want to e.g. check the size of the list and then iterate over it, while maintaining the invariant that the number you got is the same as the number of iterations you're going to do, then you have to make a defensive copy, because there's no argument type you can ask for that means "actually immutable".
[ Parent
| on HN ]
`List<T>` is technically immutable. You can make it mutable by casting to `MutableList<T>`, but that's something you have to explicitly do.