Re: hashCode
On 8/29/12 11:51 AM, markspace wrote:
On 8/29/2012 11:06 AM, Daniel Pitts wrote:
Map<MyKey, MyValue> map=new HashMap<MyKey,MyValue>(new MyKeyHasher());
Does that make more sense?
I see. You're changing the specification arbitrarily to fit your needs.
That wasn't what I had in mind. Sure, if you just assume you can do
what you like you can re-write library code, but the idea was to hash
Object, without having to supply a "MyKeyHasher".
The point is that hashing "Object" isn't entirely sensible in most
situations. Granted, there are some situation where Identity is what
you really want to key off of, but they are far fewer than a "value"
comparison. On top of that, I've often needed two different ways to
"compare" object equality, depending on the context of that comparison.
The Hasher concept would decouple the comparison from the user of the
hash, and potentially from the hashable object.
Now, just like the Comparable interface exists, a Hashable interface
could also exist, for classes which provide a "default" comparison.