I’m trying to track down an unexpected inequality between two objects, and trying to figure it out by looking at the fields manually is a little tedious
Tim Malseed
02/18/2022, 2:50 AM
Oh, got it. Using reflection:
Copy code
import kotlin.reflect.full.memberProperties
fun differingFieldNames(a: MyClass, b: MyClass): List<String> {
return MyClass::class.memberProperties.filter {
val startValue = it.get(a)
val endValue = it.get(b)
!Objects.equals(startValue, endValue)
}.map { it.name }
}
m
MrNiamh
02/18/2022, 9:50 AM
fyi if they’re both data classes, any decent testing library (hamkrest, kotest etc.) will have an equals check function which should nicely display where the difference is