Good day. I ran into the following problem. I have an extension function for type KMutableProperty0<T>, that trying to get delegate of this property by calling a method getDelegate()
@Suppress("UNCHECKED_CAST")
fun <T> KMutableProperty0<T>.getObservableVarDelegate(): ObservableVar<T> {
isAccessible = true
val delegate = getDelegate()
isAccessible = false
if (delegate == null || delegate !is ObservableVar<*>) {
throw UnsupportedDelegateException("Property ${this.name} is not an ObservableVar")
} else {
return delegate as ObservableVar<T>
}
}
In other place i run the following code:
class EntityImpl {
val amount by ObservableVar(0)
}
val entity = EntityImpl()
entity::amount.getObservableVarDelegate()
This code works fine. But if i get a property from an interface variable pointing to the same object, method getDelegate() returns null.
interface Entity {
val amount: Int
}
class EntityImpl: Entity {
override val amount by ObservableVar(0)
}
val entity: Entity = EntityImpl()
// throws an Exception because the method getDelegate() returns null
entity::amount.getObservableVarDelegate()
Do you know any available way to solve this problem?