xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- 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"
-
Re: [XOM-interest] ClassLoader issues,
Remko Popma, 09/19/2002
- Re: [XOM-interest] ClassLoader issues, John Cowan, 09/19/2002
- <Possible follow-up(s)>
-
Re: [XOM-interest] ClassLoader issues,
Remko Popma, 09/19/2002
-
Re: [XOM-interest] ClassLoader issues,
Elliotte Rusty Harold, 09/19/2002
- Re: [XOM-interest] ClassLoader issues, John Cowan, 09/19/2002
-
Re: [XOM-interest] ClassLoader issues,
Elliotte Rusty Harold, 09/19/2002
Archive powered by MHonArc 2.6.24.