I have created a function that should get a suspended function as its parameter, run it, and perform some operations with the results.
When I try to call this function and pass a function reference from a different class (let us call it "SomeClass" for example), I see the following error on intellij:
Type mismatch.
Required:
suspend (String, Int) → SomeType
Found:
KSuspendFunction3<OtherClass, String, Int, SomeType>
My function that should get a suspended function as a parameter:
private suspend fun performSomeOperation(
block: suspend (String, Int) -> SomeType
) : Result<SomeValue> {
.
.
.
}
The function I reference from "OtherClass"
suspend fun performOperation(id: String, value: Int): SomeType {
.
.
.
}
The call to my function, passing OtherClass::performSomeOperation function reference as a parameter
updateRestartParam(OtherClass::performSomeOperation)
Ok, so it appears this error was caused since I tried to pass a "Bound Callabele Reference", which means referencing a member function of a different class.
And Since Kotlin 1.1 you can do that, by prefixing the function reference operator with the instance: