(no -1 from me) That's not completely true. It's perfectly legal to only use a subset for hashCode (e.g. code and name for equals and only code for hashCode). It's even legal to use a constant hashCode (public int hashCode() {return 42;}) - it ruins the performance of hashed collections (HashMap, HashSet, ...) but they keep working correctly. So it's better than an invalid hashCode method. The only rule is: if two objects are equal (a.equals(b)) they must have the same hash code (a.hashCode() == b.hashCode()). If they aren't equal, hash codes may still be equal.
–
sfusseneggerJan 25 '10 at 14:40