jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobias Strasser <tobias.stras...@gmail.com>
Subject Re: Checkstyle improvements
Date Thu, 28 Apr 2005 09:00:10 GMT
> > > regarding missing hashCode(): i intentionally do never override hashCode()
> > > for mutable objects. hashCode() should imo only be implemented for
> > > immutable objects.

> +1 for overriding hashCode() returning a constant integer
> for mutable classes. i don't fully agree with the javadoc though.
> if you implement hashCode() 'correctly', i.e. calculate the hashcode
> based on the objects fields, you risk losing track of data in a
> hash table.
> 
> mutable objects should imo never be managed in hash tables.
> returning a constant integer is therefore fine with me for mutable
> objects.

well, when the equality depends on mutable data, the object cannot be
used in sets at all. so no need to return '1' as hashcode. if the
object cannot be used in set, i would rather throw a
UnsuportedOperationException:

public int hashCode() {
       thrown new UnsupportedOperationException("unable to compute hashcode");
}

cheers, tobi
-- 
------------------------------------------< tobias.strasser@day.com >---
Tobias Strasser, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97 
-----------------------------------------------< http://www.day.com >---

Mime
View raw message