On 9 Jun 2011, at 20:31, Mircea Markus wrote:
> And what happens if the object's hashcode is not overridden?
Or if a user-defined hashcode is poor and returns the same value for 2 keys?
In that situation user can plug-in it's own function. I rely on object's hash
only if user hasn't introduced his own value. If user doesn't do that and
object's native haschode is used then optimisation does not bring any benefit.
I don't think you can do that - you can't force a user to provide a key comparator
(you need a sensible default), nor can you ever rely on object.hashcode - even as a
fallback - since the result of object.hashcode is different on each different JVM.
It's not that it doesn't bring any benefit, it breaks one of the invariants of the
design. :-)
--
Manik Surtani
manik(a)jboss.org
twitter.com/maniksurtani
Lead, Infinispan
http://www.infinispan.org