简体   繁体   中英

what list type which is mutable in kotlin can be used in java?

Having a lib created with kotlin, in it there is a function expected to be overriden by its descendent class, which takes a mutableList (expected to be modified in this function)

protected open fun makeDataForAdapter(itemsList: MutableList<Data>) : List<Data>{
    return itemsList // default behavior
}

the lib is used in a app with java, so the descendent class overrides it:

@Override
protected List<Data> makeDataForAdapter(MutableList<Data> itemsList) {
     ......
}

the compiler complains about "cant resolve the MutableList"

what list type which is mutable in kotlin can be used in java?

The kotlin.List<out T> and kotlin.MutableList<E> are mapped types , which, on the JVM and Android, are both represented by the java.util.List<E> interface.

So you just need to use the Java List<E> type wherever you need to inter-operate with the Kotlin List<out E> or MutableList<E> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM