You cannot create class that inherits from a funct...
# coroutines
f
You cannot create class that inherits from a function
m
You can. It's just inheritance from a suspending function type that is not allowed. This compiles fine:
Copy code
class Test(val n: Int) : () -> Int {
   override fun invoke(): Int = n
}
m
suspending function has a different bytecode signature to what you declare in your
suspend fun
, hence not allowed
f
Well, I agree, but I must say you are inheriting from a kotlin interface (kotlin.Function)
d
You can inherit from kotlin.Function, use
Any?
as return type and add
Continuation<R>
parameter
t
I think this is planned for 1.40
k
while you might be able to do this, and it will probably work....from a developer perspective it would be much easier to make it a single method interface
z
Also, I’m pretty sure “inheriting from a function type” is not supported in Kotlin/JS, so this will make your code multiplatform-unfriendly.