01/23/2018, 1:26 AM
How much compatible Kotlin generics are with Java ?
sealed class NetworkResource<out ResponseType, out ErrorType> {
    class Loading<out ResponseType, out ErrorType> : NetworkResource<ResponseType, ErrorType>()
    data class Success<out ResponseType, out ErrorType>(val response: ResponseType) : NetworkResource<ResponseType, ErrorType>()
    data class Error<out ResponseType, out ErrorType>(val error: ErrorType) : NetworkResource<ResponseType, ErrorType>()

class NetworkObserver<ResponseType, ErrorType> : Observer<NetworkResource<ResponseType, ErrorType>> {}
When I use it from Java I'm getting
incompatible types: <anonymous NetworkObserver<Object,String>> cannot be converted to Observer<NetworkResource<Object,String>>
. However if I am remove
from NetworkResource it works for Java, but it messes type inference in Kotlin.
It looks like some
and looking at the bytecode do the job. I wonder if I am doing the right thing.