Maciej S
07/07/2025, 1:32 PMMaciej S
07/07/2025, 1:34 PMJoffrey
07/07/2025, 2:01 PMsuspend
in front of a regular function type:
suspend () -> Unit
is an example of a suspending function type.
You can see this sort of types in the declarations of some higher-order functions in the coroutines library, typically coroutine builders like launch
or `async`:
https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/launch.htmlMaciej S
07/07/2025, 3:23 PM@JvmInline
value class DummySuspendValue(val block: suspend () -> Unit)
...
val a = DummySuspendValue {}
val classifier = a::class.declaredMemberProperties.first().returnType.classifier
In the example above, classifier is null
. According to the docs, `classifier`:
Returns null if this type is not denotable in Kotlin, for example if it is an intersection type.
If I were to go by the reflection behaviour and the docs, I’d have to conclude that a suspending function type is in fact non-denotable.
If I remove the suspend modifier like so:
@JvmInline
value class DummySuspendValue(val block: () -> Unit)
the classifier is no longer null
.