hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laura Werner <la...@lwerner.org>
Subject Re: NameValuePair.equals
Date Mon, 08 Sep 2003 16:11:20 GMT
Ortwin Gl├╝ck wrote:

> Why is it required that equals returns false if the classes do not 
> match exactly? I thinks this is a weird behaviour for an equals method 
> and should clearly be changed.

It's weird behavior, but you have to be careful when changing it to 
instanceof.  If an equals method tries to get too clever and suports 
equality with other types,  you can end up with cases where equals is 
not symmetric, e.g. a.equals(b)==true but b.equals(a)==false.  The usual 
"if (other instanceof <ThisClass>)" is usually safe, though.

There's a good discussion of this in "Effective Java" by Josh Bloch.  I 
think this book is a must-read for anyone doing API or class library 
development in Java.

BTW, sorry I've been fairly scarce lately.  I started a new job two 
weeks ago and I'm spending lots of time trying to get up to speed and 
figure out the environment here.

-- Laura

To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org

View raw message