I'm trying to write a method that will compare the 'common properties' (sharing the same name/type) of two objects in Kotlin. Its intended to be used in tests, for comparing 'expected' with 'actual' objects that aren't of the same type.
This is a simplified version on the code so far:
val obj1Props = obj1::class.memberProperties
val obj2Props = obj2::class.memberProperties
val commonPropertyPairs = obj1Props.map { obj1Prop ->
obj1Prop to obj2Props.find { obj2Prop -> obj1Prop.name == obj2Prop.name } }
.filter { pair -> pair.second != null }
commonPropertyPairs.forEach { pair ->
pair.first.get(obj1)
}
I'm currently getting this error message under 'pair.first.get' near the bottom:
out-projected type
KProperty1<out Any, Any?>
prohibits the use ofpublic abstract fun get(receiver: T): R defined in kotlin.reflect.KProperty1
I understand that I obviously cannot use abstract methods, what should I be doing instead?