I’m trying to track down an unexpected inequality ...
# getting-started
t
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
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
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
🙌 1