sanggggg
12/19/2022, 1:32 PMclass Foo {
suspend fun bar() {
foo()
}
suspend fun foo(): Long {
delay(1000)
return 1000L;
}
}
suspend fun <T> process(fn: suspend () -> T, fn2: (T) -> Unit) {
fn2(fn())
}
suspend fun main() {
process(Foo()::bar) { println("Success") }
}
sanggggg
12/19/2022, 1:32 PMException in thread "main" java.lang.ClassCastException: class java.lang.Long cannot be cast to class kotlin.Unit (java.lang.Long is in module java.base of loader 'bootstrap'; kotlin.Unit is in unnamed module of loader 'app')
at aoc.leetcode.AppKt$main$3.invoke(App.kt:22)
at aoc.leetcode.AppKt.process(App.kt:17)
at aoc.leetcode.AppKt$process$1.invokeSuspend(App.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:178)
at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:166)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:431)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:420)
at kotlinx.coroutines.CancellableContinuationImpl.resumeUndispatched(CancellableContinuationImpl.kt:518)
at kotlinx.coroutines.EventLoopImplBase$DelayedResumeTask.run(EventLoop.common.kt:500)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:284)
at kotlinx.coroutines.DefaultExecutor.run(DefaultExecutor.kt:108)
at java.base/java.lang.Thread.run(Thread.java:829)
sanggggg
12/19/2022, 1:36 PMContinuationImpl
. (Instead, it returns inner suspend function immediately without considering the type of it.)
The above can be found through the decompiled code of the following three functions.Sam
12/19/2022, 1:38 PMsanggggg
12/19/2022, 1:38 PM