users@jaxb.java.net

Re: hashCode

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Wed, 08 Jan 2003 09:15:54 -0800

> I was wondering if there is a way to make the compiler generate equals
> and hashCode() implementation based on the content of the element. This
> used to be present in the DTD-beta release but has disappeared with this
> one.

Because of the difficulty in correctly implementing the equals and the
hashCode methods for value-based equality (plus performance issue), we
decided not to do this. So no, there's no switch/customization.

As a workaround, you could implement it externally. You can define a
comparator:

class Comparator {
  static boolean equals( MyObject a, MyObject b ) {
    ...
  }
  static int hashCode( MyObject a ) {
    ...
  }
}



One of our justifications to drop this was that the DOM doesn't
implement it either. My personal experience also suggests that I rarely
implement the value-based equals/hashCode method for larger classes.


regards,
--
Kohsuke KAWAGUCHI                  408-276-7063 (x17063)
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com