News for hackers. Stuff that matters.
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".
Re:Kotlin 1.2.20 released by relics443 on Wednesday January 17, 2018 @11:43AM (#16169351)
`List<T>` is technically immutable. You can make it mutable by casting to `MutableList<T>`, but that's something you have to explicitly do.
Re:Kotlin 1.2.20 released by lmm on Wednesday January 17, 2018 @11:56AM (#16169516)
It's not immutable, it's something analogous to C const: you can't mutate it, but it can be mutated under you. If you call .size() on it twice you might get different results.