Reputation: 2527
Why following signature gives Unsupported [suspend operator "getValue"]
compilation error?
suspend operator fun getValue(thisRef: Any?, property: KProperty<*>): T
Is it because of any technical limitation?
Upvotes: 3
Views: 1813
Reputation: 198093
The getValue
operator is for implementing the getter of a val
, and there is no such thing as a suspend val
-- only a normal val
.
A suspend fun
can't be called directly from a normal function, like the implementation of a getter -- so this getValue
can't be used for its intended purpose. Kotlin warns you of that by giving a compile error on an attempt to create a suspend operator fun getValue
.
Upvotes: 7