Discussion - another method for comparing content equality in place of `Item.equals()`
See original GitHub issueI’d like to start making more quality of life improvements in the library.
Currently to do a content comparison of two Item
s which are the same (meaning, isSameAs
returned true for them) Groupie uses the Java equals
method.
This forces subclasses to override both equals
and hashCode
for correct implementations and creates unnecessary boilerplate. This is especially nasty in Kotlin projects which 99% of the time don’t ever override equals thanks to data classes.
In the interest of a nicer API, I’d like to create a companion function to isSameAs
that will be used for the areContentsTheSame
DiffUtil callback.
My proposed name is hasSameContentAs
but open to other suggestions. areContentsTheSame
is also an option but then the name would be different from isSameAs
.
Whatever that function is called the default implementation would use the equals
to not break current implementations.
Thoughts?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top GitHub Comments
I think it’s a good idea, overriding hashCode() just for this reason can be a pain and shouldn’t be necessary. hasSameContentAs() sounds good to me.
Now deployed in
2.6.0
- thank you for the feedback