How to Write an Equality Method in Java
Martin Odersky, Lex Spoon, and Bill Venners have written an article on How to Write an Equality Method in Java. Given the amount of traffic my post on the same topic has attracted, I thought I might take a look. Their solution is the best I have seen, and well worth a look, but the article suffers the same problem as every article I've read on this topic: it fails to properly define equals().
A Java equals() method should implement a test for bisimulation.
To me, the remarkable thing about the Artima article is that it provides and example where the traditional getClass() approach I have previously recommended fails to implement bisimulation. The good-news is that this is a rather artificial use-case, and as such isn't going to be causing many bugs. The bad-news is that the fix requires a helper method defined at the topmost concrete class, and the need for it isn't intuitive.
Anyway, if you program in Java you need to read and understand this article.



2 Comments:
Hey, you could at least have the decency to link the previous article.
By
Patrick, at 3:31 am, July 11, 2009
A 'business shopper' is purchasing for an association,right here and the choice will presumably influence not just progressively individuals however the business itself.
By
ADmin, at 6:17 pm, March 19, 2013
Post a Comment
<< Home