thiagoretondar
07/06/2019, 1:47 AMdata class
instances? One by one?gildor
07/06/2019, 2:12 AMLeo Na
07/06/2019, 3:20 AMgildor
07/06/2019, 6:47 AMigor.wojda
07/06/2019, 1:56 PMhashCode
and equals
, however they are usually pain to maintain (one of the reasons why we have data classes in Kotlin)
Another thing would be what @Leo Na suggested (should be good if you don’t use toString
or want to override it)
You could also store class properties in the list but this would only help you in very specific scenarios
data class Foo(val name: String, val age: Int)
val properties = listOf(Foo::name, Foo::age)
properties.forEach { it.name }
On top of that you can use reflection to list object properties (and compare with another object)
instance::class.memberProperties.forEach { println(it.name) }