MutableList vs List

I was looking into the problem of SingletonList.

problem of SingletonList
val a = listOf("")
if(a is MutableList){
   a.add("ded")
}

throws UnSupportedOperationException.

The SingletonList is immutable, so it should not implement MutableList.

When I did this, i came across the following quote on https://youtrack.jetbrains.com/issue/KT-15126#tab=Comments:

The distinction between List and MutableList exists only at compile time. At runtime they become the same type.

Is it possible to add a interface in Java which a collection can implement at runtime to keep this information or can be added in a Java project to support this?

1 Like

Most Kotlin programs use regular Java collection classes, which are part of the JDK and do not implement any Kotlin-specific interfaces. Therefore, it’s not clear how it would be useful to define such an additional interface.