Hi, How to figure out this compiler error? ```Type...
# getting-started
m
Hi, How to figure out this compiler error?
Copy code
Type parameter output is declared as 'out' but occurs in 'invariant' position in type Flow<PagingData<output>>

abstract class PaginatedFlowUseCase<in Input, out output>(
    private val dispatcher: CoroutineDispatcher
) {
    operator fun invoke(input: Input): Flow<PagingData<output>> {
        return execute(input).flowOn(dispatcher)
    }

    protected abstract fun execute(input: Input): Flow<PagingData<output>>
}
But it works when changing PagingData to kolin.Result class
y
It's likely that
PagingData
is declared with an invariant type parameter. You can either make
output
invariant by removing
out
, or you can replace
Flow<PagingData<output>>
with
Flow<PagingData<out output>>
. Also, please use PascalCase for your type parameters, it's the usual convention, so
Output
instead of
output
.
m
Copy code
abstract class PaginatedFlowUseCase<in Input, Output>(
    private val dispatcher: CoroutineDispatcher
) {
    operator fun invoke(input: Input): Flow<PagingData<Output>> {
        return execute(input).flowOn(dispatcher)
    }

    protected abstract fun execute(input: Input): Flow<PagingData<Output>>
}
Type argument is not within its bound Expected: Any Found: Output
s
i'm 80% sure that the issue is, that you didn't limit
Output
to extend from nonnullable
Any
(right now it's
Any?
by default). Try
abstract class PaginatedFlowUseCase<in Input, Output: Any>
m
Thanks, Stephan that works.