commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hendrik Maryns <>
Subject Bad design in
Date Thu, 08 Jun 2006 23:42:33 GMT
Hash: SHA1


I want to use ReferenceMap, and am working on a Java 1.5 project, where
I heavily use generics.  So I decided to generify (part of) the commons
collections classes.  While doing so, I stumbled on a problem that would
not be generified.  The reason for this is bad design.

The class AbstractHashedMap.KeySetIterator inherits from
EntrySetIterator.  But the return types of those two are, when
generified, incompatible.  To be able to make them generic, all those
protected static inner classes first have to be made non-static (such
that they have access to the type of key and value from the parent
list).  Then, the appropriate extension has to be chosen.  For
EntrySetIterator, this would be HashIterator<Map.Entry<K,V>>.  But
KeySetIterator extends this, which implies its next() method would
return a Map.Entry<K,V>.  This is not what we want.  Instead, we want it
to inherit from HashIterator<K>.  And indeed, this is the simple
solution: just have it extend HashIterator<K>.

So if this is the correct (I hope) solution with generics, I suppose the
same is true without generics.

Now that we talk about it, is there a reason other than ‘Nobody has
taken the time to convert yet’ that the Jakarta Commons Collections do
not use 1.5 generics?  Is it useful to generify it?  (I would be
prepared to send in that which I am doing now.)

I am not subscribed to the mailing list, please CC me.

Cheers, H.
- --
Hendrik Maryns
Herrenberger Straße 40
D-72070 Tübingen
+49707143783    (Deutschland fest)
+491753353494    (Deutschland Handy)
+32485470741    (België)

=================    (waarom zou ik hier toch naar verwijzen...)        De kunst van het stedelijke oorlogvoeren
Version: GnuPG v1.4.2 (GNU/Linux)


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message