Reputation: 1016
Using reflection I can iterate through my attributes:
data class AnotherDataClass(
val property: String,
val dataClass: DataClass
)
AnotherDataClass::class.memberProperties.filter {
return it::class.isData
}
But it::class.isData
is always false since the type of it
is jvm.internal.KProperty1Impl
. Is there a way to check if this class is a data class?
Upvotes: 0
Views: 1682
Reputation: 3890
Use
AnotherDataClass::class.memberProperties.filter {
(it.returnType.classifier as? KClass<*>)?.isData ?: false
}
Upvotes: 2