About #kotlin

Kotlin 'equals ignoring fields' using data classes

#kotlin / Nov 28, 2023 / 4 min
Equals ignoring fields is a pretty common operation. While often used within the test code to exclude selected fields from equality assertions, it can also be handy in our domain code. With Kotlin data classes, we can implement equals ignoring fields without using reflection or extra libraries. This solution feels almost too simple to describe, but it’s interesting to compare it with the available alternatives. Status quo Let’s take a simple blog post representation as an example:
Read the article