Suppose there is a class and i need to detect reflectively which of its properties have custom accessors (getters/setters). For example: the job
has, while name
hasn’t.
class GuineaPig {
var name: String = "Betsy"
var job: String = "Spin the wheel"
get() = field
set(value) { field = value + " for food" }
}
In this case i research GuineaPig::class. Reflect its memberProperties. Find a KProperty of name
and job
. And fall into despair… because can not find any means to detect whether one’s accessors are defined by user code or generated as defaults by the compiler.
I guess that in run-time there is no difference between custom and default accessors. But why have that powerful reflection package that isn’t capable of doing that task. Of course it’s may be me who just doesn’t know how to do it. Anyway is there any solution?
Why? Let’s say i know that reflective call (get/set) to javaField of a property directly is twice faster than using KCallable.call. However if i use javaField of a property with user defined getter/setter i may break its logic. So i need to distinguish which property has custom accessors.
Remark: Guinea pig is taken for clarity. I’m against tests on animals.