Why compareTo () should be consistent to equals () method in Java?

2) CompareTo must be in consistent with equals method e.g. if two objects are equal via equals() , there compareTo() must return zero otherwise if those objects are stored in SortedSet or SortedMap they will not behave properly .

Sizin İçin Seçtik  Is string comparable Java?

Leave a Reply

Your email address will not be published. Required fields are marked *

Why compareTo () should be consistent to equals () method in Java?

2) CompareTo must be in consistent with equals method e.g. if two objects are equal via equals() , there compareTo() must return zero otherwise if those objects are stored in SortedSet or SortedMap they will not behave properly .

Sizin İçin Seçtik  Can you use == to compare objects in Java?

Leave a Reply

Your email address will not be published. Required fields are marked *