https://kotlinlang.org logo
m

Michael Böiers

05/28/2021, 12:44 PM
Just ran across this, which throws an `UnsupportedOperationException`:
Copy code
val list = listOf(1, 2)
if (list is MutableList) list.add(3)
https://pl.kotl.in/_jfhJy6is Why is that? I mean, I get that the list is immutable, but why then can it be cast to MutableList?
m

Michael Böiers

05/28/2021, 12:57 PM
I see, thanks! So the terrible blunders of the old Java world live on in Kotlin (JVM) 🙂