question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion - another method for comparing content equality in place of `Item.equals()`

See original GitHub issue

I’d like to start making more quality of life improvements in the library.

Currently to do a content comparison of two Items 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:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
scorpeeoncommented, Sep 18, 2019

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.

0reactions
ValCanBuildcommented, Sep 24, 2019

Now deployed in 2.6.0 - thank you for the feedback

Read more comments on GitHub >

github_iconTop Results From Across the Web

Difference between comparing String using == and .equals ...
Both equals() method and the == operator are used to compare two objects in Java. == is an operator and equals() is method....
Read more >
Object.Equals Method (System) - Microsoft Learn
method is equivalent to a call to the ReferenceEquals method. Reference equality means that the object variables that are compared refer to the...
Read more >
[Solved] Discussion Forum question The class Object defines ...
The class Object defines an equals() method to compare objects. Specify the advantages and disadvantages of using this method and suggest an ...
Read more >
How and Why to Override the equals Method in Java
Often in Java programs you need to compare two objects to determine if they are equal or not. It turns out there are...
Read more >
Comparing Java objects with equals() and hashcode()
If an object's hashcode is not the same as another object's hashcode, there is no reason to execute the equals() method: you just...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found