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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to