1.

What Happens If Equals() Is Not Consistent With Compare To() Method?

Answer»

This is an interesting questions, which ASKED along with equals() and hashCode() contract. Some java.util.Set implementation e.g. SortedSet or it's concrete implementation TREESET uses compareTo() method for comparing OBJECTS. If compareTo() is not consistent means doesn't return zero, if equals() method returns true, it may break Set contract, which is not to avoid any DUPLICATES.

This is an interesting questions, which asked along with equals() and hashCode() contract. Some java.util.Set implementation e.g. SortedSet or it's concrete implementation TreeSet uses compareTo() method for comparing objects. If compareTo() is not consistent means doesn't return zero, if equals() method returns true, it may break Set contract, which is not to avoid any duplicates.



Discussion

No Comment Found