N
Neroku
Well, I know equals() and compareTo() could behave different to test
for equality, it just depend on the way I implement them, but, Would it
be a bad practice to rewrite equals() and compareTo() so they behave in
the following way:
- Two different instances of the same class hold different attribute
values, calling equals() return false comparing both objects because
they are not the same, but compareTo() return 0, since this is the
sorting criteria I want (a desired attribute match).
or even
- Two different objects of the same class hold the same attribute
values, this is, they are internally equals, and calling equals()
return false because the are different instances (the references are
not the same), but calling compareTo() return 0, since all attributes
contain the same value.
Thanks in Advanced
for equality, it just depend on the way I implement them, but, Would it
be a bad practice to rewrite equals() and compareTo() so they behave in
the following way:
- Two different instances of the same class hold different attribute
values, calling equals() return false comparing both objects because
they are not the same, but compareTo() return 0, since this is the
sorting criteria I want (a desired attribute match).
or even
- Two different objects of the same class hold the same attribute
values, this is, they are internally equals, and calling equals()
return false because the are different instances (the references are
not the same), but calling compareTo() return 0, since all attributes
contain the same value.
Thanks in Advanced