Is this a bug that `Collections.singletonList()` i...
# announcements
d
Is this a bug that
Collections.singletonList()
is seen as a
MutableList
in Kotlin?
🤔 3
j
I think the translation between Java and Kotlin might be the problem here
How would Kotlin understand a Java Collection is immutable?
In the end a Collections.singletonList returns a Java List<>, which has mutable properties
and then I guess it doesn't matter to the compiler that under the hood it will just crash if you try to edit the list
d
Yep, thought as much - the thing is in certain circumstances you get something that Kotlin just tells you is a
List
and you don’t exactly know where this comes from.
And to make matters more pressing, the original list I got was from Kotlin itself, because I have no Java code I interop with in this particular place.
i.e.
listOf
is defined as
public fun <T> listOf(element: T): List<T> = java.util.Collections.singletonList(element)
e
you may define your original one which has @UnmodifiableView and import it?