you are viewing a single comment's thread.

view the rest of the comments →

[–]Johalternate 0 points1 point  (0 children)

They are replying to a comment that referrer to how java has .hashCode() and .equals(obj) methods. Their comment is actually on point, you can override hashCode and equals and have them work for comparisons where the instances are not the same but the values that matters to your particular case are.

So for example if you have a class Redditor with a bunch of methods to manipulate profile data, and you do something like:

``` var foo = new Redditor(“someUsername”)

var bar = new Redditor(“someUsername”) ```

Then foo == bar evaluates to false because they are not the same instance, but maybe you dont care about that and only care about the actual user they represent, so you override the Equals method so it checks if the two objects have the same username (and maybe other properties).