I want to create on-the-fly objects using object expressions but I would like to compare them by their contents. Is there an easy way to write it without implementing equals
and hashCode
?
To make it more concrete, what would be the smallest change to make the assertion of this test pass?
@Test
fun `an object comparison test`() {
val obj1 = object {
val x = 1
}
val obj2 = object {
val x = 1
}
assertEquals<Any>(obj1, obj2)
}