Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] ClassLoader issues

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: John Cowan <jcowan AT reutershealth.com>
  • To: remko.popma AT azzurri.jp (Remko Popma)
  • Cc: XOM-interest AT lists.ibiblio.org (XOM-interest)
  • Subject: Re: [XOM-interest] ClassLoader issues
  • Date: Thu, 19 Sep 2002 13:33:31 -0400 (EDT)

Remko Popma scripsit:

> 1) Is this really a typesafe enum issue?
> Basically, as far as I understand it, neither the == operator nor the
> equals() method works if you compare two instances loaded by separate
> classloaders. So eg. someNode.equals(sameNodeLoadedByOtherClassloader)
> would also return false.

Typesafe enums are in competition with plain old integers, which don't care
about class loaders. So yes, it's a typesafe enum issue in that you don't
get the expected results with enums whereas you do with ints.

Here's a possibility:

int theCode;

private SomeEnumClass(int code) {theCode = code;}
public int hashCode {return theCode;}
public boolean equals(Object o) {
if
(!o.getClass().getName().equals("blah.blah.SomeEnumClass")) {
return false;
}
else {
return theCode == o.hashCode();
}

Note the importance of testing the class *name* for equality, not the
class object. That way, we do the hashCode check iff this is the same
class independent of class loaders.

--
John Cowan <jcowan AT reutershealth.com>
http://www.reutershealth.com http://www.ccil.org/~cowan
Yakka foob mog. Grug pubbawup zink wattoom gazork. Chumble spuzz.
-- Calvin, giving Newton's First Law "in his own words"




Archive powered by MHonArc 2.6.24.

Top of Page