Java: Set<E> collection, where items are identified by its class

Posted by mschayna on Stack Overflow See other posts from Stack Overflow or by mschayna
Published on 2010-03-15T10:44:41Z Indexed on 2010/03/15 10:49 UTC
Read the original article Hit count: 299

Filed under:
|
|
|
|

I need Set collection, where its items will be identified by items class. Something like ReferenceIdentityMap from Appache Collections, but on class scope i.e. two different instances of same class must be identified as same in this collection.

You know, it is a violation of equals()/hashCode() identity principle but in occasional use it makes sense.

I have done this in simple class backing with Map<Class<? extends E>, E>, but due to simplicity it doesn't implement Set<E>. There may be a more elegant solution, decorator of any Set<E> would be great.

Is there any implementation of such collection there (Apache/Google/something/... Collections)?

© Stack Overflow or respective owner

Related posts about java

Related posts about set