Kotlin Generics Error in Java

M-WaJeEh :

Given the following three kotlin classes:

abstract class UseCase<T> {
    fun execute(action: Action<T>) {
    }
}

class ConcreteUseCase : UseCase<List<String>>()

class Action<T>

I am unable to compile following lines in java code:

ConcreteUseCase s = new ConcreteUseCase();
s.execute(new Action<List<String>>());//<<<<<<< compilation error

enter image description here

Error says:

SomeClass<java.util.List<? extends Type>> in Class cannot be applied to SomeClass<java.util.List<Type>>

I am still new to kotlin and this might be something very small but I can't seem to figure it out. I will appreciate any help.

hluhovskyi :

Change your ConcreteUseCase as following:

class ConcreteUseCase : UseCase<List<@JvmSuppressWildcards String>>()

For more information visit this link

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=438801&siteId=1