« Return to Thread: 2.8 collections

Re: 2.8 collections

by Jesper Nordenberg :: Rate this Message:

Reply to Author | View in Thread

Ben Jackman wrote:
> I had a few thoughts concerning some things on page 15, It's kind of long so
> I posted it to my blog, generally I am concerned about the mutable
> collections throwing UnsupportedOperationException when their hashCode
> method is called. (It violates the equals/hashCode contract and could be a
> nasty gotcha)

Agreed, this is a bad idea. Mutable collections are perfectly usable as
hash table keys provided their equals() implementation uses an object
identity check (the default Object.equals() implementation). I'd much
prefer an addition of a separate "equalElements" or similar method that
checks for momentary element equality.

What's the rationale behind the current implementation of mutable
collections equals()?

/Jesper Nordenberg

 « Return to Thread: 2.8 collections