Pablo Schmid
08/17/2021, 10:36 PMdata class MyClass(val person: Person)
. When MyClass is instantiated, it's built with a PersonImpl as the Person is the interface. val result = MyClass(PersonImpl())
I need to dynamically know that the person attribute is a PersonImpl.
I have been trying with `result::class.declaredMemberProperties`but I can't get the PersonImpl from it.
ThanksBen Woodworth
08/17/2021, 10:47 PMresult.person is PersonImpl
, or using result.person::class
?Pablo Schmid
08/17/2021, 10:56 PMBen Woodworth
08/17/2021, 11:49 PMfun Any.hasPersonImplPropertyValue(): Boolean =
this::class.declaredMemberProperties.any { property ->
(property as KProperty1<Any, *>).get(this) is PersonImpl
}
result.hasPersonImplPropertyValue() // true
(I'm not sure how to get around the hacky-feeling as KProperty1<Any, *>
cast so there might be a better way)Pablo Schmid
08/18/2021, 12:11 AM