2

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?

5
  • 1
    List<Data>... Just use Ctrl-I (Cmd-I on Mac), and IntelliJ will allow you to override methods, and will add the necessary code for you. Commented Aug 21, 2018 at 17:04
  • Thanks @JB Nizet, clicking Cmd-I on where? I am using AndroidStudio, seems it does not anything? Commented Aug 21, 2018 at 17:21
  • Sorry, it's Ctrl-O, for Override method, in the Java subclass. Commented Aug 21, 2018 at 17:22
  • doesnt work in androidstudio, Cmd-O opens the class file. Commented Aug 21, 2018 at 17:29
  • It's Ctrl-O, not Cmd-O Commented Aug 21, 2018 at 17:53

1 Answer 1

4

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>.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.