Wondering what needs to be done for listed method
public final int compareTo(final FieldDTO o) {
return o.available.compareTo(this.available);
its throwing exception on line 2 stating
Bad practice - Class defines compareTo(...) and uses Object.equals() 16 days
field defines compareTo(FieldDTO) and uses Object.equals()
Not sure how should i handle this. Thanks in advance.
If you define compareTo
you should at least define equals
boolean equals(it) {
return compareTo(it) == 0;
}
otherwise you will get strange problems when you put your object in Map
s and Set
s. It is generally good practice to also define hashCode
.
you need to override Object class equals() and hashCode() methods. Use IDE generated code for these, it will pull all the Object attributes and creates method for you.
On eclipse IDE:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With