Equality for data classes w/ arrays

Equality rules are quite straightforward: classes by identity, data classes by content. Kotlin generates equals() implementation based on the properties of the data class. However this doesn’t help for primitive arrays: we have to override equals() to compare their contents. What if we had an annotation on either class or field to enable this? It could be a compiler plugin but it’s also something related to lints so maybe it should be shipped by default?

1 Like

Here’s the StackOverflow answer on comparing array content (tl:dr use contentEquals and contentDeepEquals)

thanks, I’m not looking for a solution, I’m proposing a change to allow automating this for data classes.

You may also be interested in this (somewhat older) blog post on data class design and limitations. And the recent Kotlin 1.4 online event on value types.

1 Like