I've encountered quite a strange behaviour: ```val...
# getting-started
d
I've encountered quite a strange behaviour:
Copy code
val l1 = listOf(1) + listOf(2)
val l2 = listOf(1, 2)
println(l1::class) // prints java.util.ArrayList
println(l2::class) // prints java.util.Arrays$ArrayList
Is this expected? The reason why it bothers me is described here https://kotlinlang.slack.com/archives/C9EJFT6DB/p1717662793347379.
s
Expected, but not important. The type returned by
listOf()
is an implementation detail. In the unlikely event you care about the actual type of list, you can always instantiate the type you want directly. I explained more about the two different classes in my reply to your other thread.
☝️ 1
e
Copy code
listOf(Unit)::class != listOf(*arrayOf(Unit))::class
this is an implementation detail you are not supposed to care about.
🤯 1
very nice 1
d
Got it!