Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Tuesday, June 9, 2009

How to Write an Equality Method in Java

Essential article on how to avoid common pitfalls and preserve the contract of equals() when writing an equality method in Java.
Class java.lang.Object defines an equals method, which subclasses may override. Unfortunately, it turns out that writing a correct equality method is surprisingly difficult in object-oriented languages. In fact, after studying a large body of Java code, the authors of a 2007 paper concluded that almost all implementations of equals methods are faulty.