Let\'s have a class Person. Person has a name and height.
Person
Equals and hashCode() takes into account only name. Person is comparable (or we implement co
you can fix it by using name for another comparison when the heights are equal
@Override public int compareTo(Person o) { if(height == o.height)return name.compareTo(o.name); return Integer.compare(height, o.height); }
since names are unique this will only return 0 if this.equals(o)
this.equals(o)