Take this simple example:
suspend fun functionA(param: Int): String {
return "hello $param"
}
When compiled, the Kotlin compiler transforms it to something like:
public static final Object functionA(int param, Continuation super String> $completion) {
return "hello " + param;
}
- An extra parameter of type
Continuation
was added. - The return type changed from
String
toObject
(orAny?
in Kotlin), because: - If the function completes synchronously, it returns the result (e.g.,
"hello 5"
) - If it suspends, it returns a special marker:
COROUTINE_SUSPENDED
This transformation enables the compiler to treat the function as a suspendable computation, not just a regular method call.