我创建了一个函数,它应该获取一个挂起的函数作为它的参数,运行它,并对结果执行一些操作。
当我尝试调用此函数并传递来自不同类的函数引用时(例如,我们称其为“SomeClass”),我在 intellij 上看到以下错误:
Type mismatch.
Required:
suspend (String, Int) → SomeType
Found:
KSuspendFunction3<OtherClass, String, Int, SomeType>
我的函数应该获得一个挂起的函数作为参数:
private suspend fun performSomeOperation(
block: suspend (String, Int) -> SomeType
) : Result<SomeValue> {
.
.
.
}
我从“OtherClass”引用的函数
suspend fun performOperation(id: String, value: Int): SomeType {
.
.
.
}
对我的函数的调用,将OtherClass::performSomeOperation函数引用作为参数传递
updateRestartParam(OtherClass::performSomeOperation)