Failing to do so breaks the equals contract and produces erratic behavior when
using WebURLs in hash-based collections (HashMap, HashSet, etc), since buckets
will be based on the default Object.hashCode() method, which is not what we
want to ensure that hashmap lookup works consistently right. According to Java
API Docs:
As much as is reasonably practical, the hashCode method defined by class Object
does return distinct integers for distinct objects. (This is typically
implemented by converting **the internal address of the object into an
integer**, but this implementation technique is not required by the JavaTM
programming language.)
An appropriate hashCode() method using the same state as the current
equals(Object) method might be:
@Override
public int hashCode() {
int hash = 3;
hash = 41 * hash + (this.url != null ? this.url.hashCode() : 0);
return hash;
}
What version of the product are you using?
3.4.1-SNAPSHOT
Please provide any additional information below.
http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html#hashCode()
http://books.google.com.ar/books?id=ka2VUBqHiWkC&pg=PA45&lpg=PA45&dq=effective+j
ava+override+hashCode&source=bl&ots=yYHhOmw_S2&sig=eDhb9_-Yv_qu7-Kjkk4au7leFHI&h
l=en&sa=X&ei=D2agUPTUKo3S9ASs7YHwCQ&ved=0CEEQ6AEwBQ#v=onepage&q=effective%20java
%20override%20hashCode&f=false
Original issue reported on code.google.com by lisandr...@gmail.com on 12 Nov 2012 at 3:08
Original issue reported on code.google.com by
lisandr...@gmail.com
on 12 Nov 2012 at 3:08