Affine transforms - matrix algebra: equals
Martin Desruisseaux
martin.desruisseaux at geomatys.fr
Tue Aug 21 10:50:37 PDT 2012
Hello all
Le 22/08/12 02:34, Pavel Safrata a écrit :
> there are some requests for implementing Transform.equals().
> Determining whether or not two transforms equal may indeed be useful.
> The question is: do we want to implement equals() and hashCode() and
> thereby break usage of (mutable) Transforms in hash-based collections?
> Or would some transformEquals(Transform) method do? I like neither of
> those options. I would probably do as much as possible to avoid
> implementing hashCode() for mutable objects but let me first hear some
> opinions on this..
I think that implementing equals(Object) without hashCode() would bring
more trouble, since it would break the contract that a.equals(b) implies
a.hashCode() == b.hashCode(). It may also cause some inconsistent
behaviour in HashMap.get(a), which may or may not find b depending on
whatever "by chance" the two Transforms have been put in the same slot
(even if they have different hash code value).
I think that a more conventional approach would be to implement both
equals(Object) and hashCode(). There is plenty of mutable JDK classes
implementing those methods (including HashMap itself! and all other
standard collection implementations), so I would tend to believe that a
majority of experienced Java developers know that they must not change
any object stored as keys in such map...
Martin
More information about the openjfx-dev
mailing list