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  Proton ve nötron ne demek?

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  What is an equals method in Java?

Leave a Reply

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