Hello, I am working on an Android project that combines Kotlin and Java (generated code by Room library). I am trying to do some generic data access objects.
In Kotlin, this code compiles correctly:
data class Entity(val name: String = "")
interface ExampleBaseInterface<T: Any> {
fun foo(): Flow<T>
}
abstract class ExampleAbstract<T: Any>: ExampleBaseInterface<T> {
override fun foo(): Flow<T> = TODO()
}
abstract class ExampleAbstractList<T: Any>: ExampleBaseInterface<List<T>> {
override fun foo(): Flow<List<T>> = TODO()
}
class ExampleClassList: ExampleAbstractList<Entity>()
When using Room library it generates Java code that looks similar to this example -it also gives a compilation error without Room, writing the Java class manually-:
public class ExampleJava extends ExampleAbstractList<Entity> { ... }
This code generates a compilation error ExampleJava is not abstract and does not override abstract method foo() in ExampleBaseInterface
If I change foo(): Flow<List<T>>
in the interface it works but my intention is to be able to use foo()
with T
and with List<T>
parameters like the Kotlin example. Do you know if it is possible?