Hello. What is the implementation of List interfac...
# getting-started
g
Hello. What is the implementation of List interface on MacOS native?
For example I can see on JVM that it is class java.util.Arrays$ArrayList but on native this code
Copy code
fun main() {
    val list = listOfString("asdf", "asdf", "asdf")
    println(list::class)
    println(" Multiplatform CLI: ${getWorld()}")
}
prints
class kotlin.collections.asList$1
. what is that asList? is it really a class?
Also why it is not directly class java.util.ArrayList instead of class java.util.Arrays$ArrayList on JVM?
c
It can't be
java.util.ArrayList
because that's a Java class, and Java classes are not available on Native. It could however be
kotlin.collections.ArrayList
. The implementation of
listOf
is:
Copy code
fun <T> listOf(vararg elements: T): List<T> = 
    if (elements.size > 0) elements.asList() else emptyList()
and
asList
is platform-dependent (it's a Java ArrayList on the JVM, and some other kinds of list on other platforms).
Does it matter which exact implementation is used though? They all behave the same.
g
no it was just interesting
so Kotlin also has its own list called
kotlin.collections.ArrayList
?
👍 1
e
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-array-list/ is an alias to
java.util.ArrayList
on JVM and an actual class on other platforms
kodee loving 1
e
Just to add regarding
Also why it is not directly class java.util.ArrayList instead of class java.util.Arrays$ArrayList on JVM?
java.util.ArrayList
and
java.util.Arrays$ArrayList
are two entirely different classes on the JVM.
They just happen to share the same simple name (
ArrayList
) which causes a confusion
kodee loving 1