Hi guys I have a such interface ```interface Requ...
# announcements
e
Hi guys I have a such interface
Copy code
interface 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
Copy code
class ConstantRequestsExecutor<T : Any> (
        private val responseValue: T
) : RequestsExecutor {
    override fun close() {
    }

    override suspend fun execute(request: Request<T>): T {
        return responseValue
    }
}
s
Is possible to implement 
ConstantRequestsExecutor
  to satisfy the interface and use T parameter on the class level?
no
not as currently defined
if you do not control this interface, then you cannot do what you’re trying to do
a
ConstantRequestsExecutor<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 site
that method as defined on the interface is required to be able to take a
Request<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 parameter
e
Yeah make sense, thanks
👍 1