Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the Java ArrayList compatible with Kotlins List interface

Tags:

kotlin

Why is this working

val foo: kotlin.collections.List<String> = java.util.ArrayList()

The ArrayList is not inheriting the Kotlin List, is it?

like image 846
guenhter Avatar asked Mar 22 '18 19:03

guenhter


1 Answers

That's because kotlin.collections.List, among other types, is a mapped type: during compilation for the JVM, its usages are compiled into the corresponding usages of the Java java.util.List interface.

like image 175
hotkey Avatar answered Sep 28 '22 06:09

hotkey