Eugene Freeman
07/20/2020, 4:41 PMinterface RequestsExecutor : Closeable {
suspend fun <T : Any> execute(request: Request<T>): T
}
Is possible to implement ConstantRequestsExecutor
to satisfy the interface and use T parameter on the class level? Thanks
class ConstantRequestsExecutor<T : Any> (
private val responseValue: T
) : RequestsExecutor {
override fun close() {
}
override suspend fun execute(request: Request<T>): T {
return responseValue
}
}
Shawn
07/20/2020, 4:57 PMIs possible to implementnoto satisfy the interface and use T parameter on the class level?ConstantRequestsExecutor
Shawn
07/20/2020, 4:57 PMShawn
07/20/2020, 4:58 PMShawn
07/20/2020, 5:02 PMConstantRequestsExecutor<Foo>
would present a fun execute(Request<Foo>)
which would not satisfy the same contract as the one declared RequestsExecutor
, which has an execute method that takes Request<T>
and T
is only declared to be bound by Any
at the call siteShawn
07/20/2020, 5:05 PMRequest<Bar>
, a Request<Baz>
, etc on any instance — if the interface were changed to RequestsExecutor<T>
then you’d be able to use the class-level parameterEugene Freeman
07/20/2020, 5:28 PM