Hi,
I would like to access a function defined on my delegate:
class Delegate : ReadOnlyProperty<Any, Int> {
override fun getValue(thisRef: Any, property: KProperty<*>): Int {
return 12
}
fun f() {}
}
class Provider {
operator fun provideDelegate(thisRef: Any, prop: KProperty<*>): Delegate {
prop.isAccessible = true
return Delegate()
}
}
class MyClass {
val x by Provider()
}
fun main() {
val c = MyClass()
val d = c::x.getDelegate()
}
The problem is that getDelegate()
throws this:
kotlin.reflect.full.IllegalPropertyDelegateAccessException: Cannot obtain the delegate of a non-accessible property. Use "isAccessible = true" to make the property accessible
Not sure what else I can do to make the delegate “accessible”.
On a broader topic, I would love to be able to call c::x.f()
as simply as this. Any way this could be done (or any plans to make it happen)?
Thank you.