是否可以在 kotlin 中扩展挂起功能?
Is it possible to extend a suspend function in kotlin?
如何扩展一个支持协程的函数?
我现在拥有的:
class MyClass : (String, String) -> Int {
override fun invoke(username: String, password: String): Int {
//method implementation
}
}
我想要的:
class MyClass : (String, String) -> Int {
override suspend fun invoke(username: String, password: String): Int {
//method implementation
}
}
如果没有将函数明确定义为函数式接口,这可能吗?
此功能尚不支持,kotlin 1.6 将支持该功能
现在支持将您的 class 扩展到 class MyClass: suspend -> Unit
如何扩展一个支持协程的函数?
我现在拥有的:
class MyClass : (String, String) -> Int {
override fun invoke(username: String, password: String): Int {
//method implementation
}
}
我想要的:
class MyClass : (String, String) -> Int {
override suspend fun invoke(username: String, password: String): Int {
//method implementation
}
}
如果没有将函数明确定义为函数式接口,这可能吗?
此功能尚不支持,kotlin 1.6 将支持该功能
现在支持将您的 class 扩展到 class MyClass: suspend -> Unit