cast a capture-of ? to a named class

Howdy,

I'm reading an ObjectInputStream that contains several classes that derive from EventListener. I now want them to add to my current class that derives form EventListenerList. Problem now is, that it all has to be Java 1.5 and so the add() method of the EventListenerList needs <T extends EventListener> add(Class<T> t, T l).

Now I only got a working snippet for prev 1.5 that look like that:

while (null != (listenerTypeOrNull = s.readObject())){

EventListener l = (EventListener) s.readObject();

add((Class<EventListener>) Class.forName((String)listenerTypeOrNull), l);

}

As I said, the read objects (listenerTypeOrNull) are classes that derive from EventListener, so I want to add them as EventListener to the EventListenerList class. But the cast to Class<EventListener> produces a warning that it is checking against the erased type Class.

So, is here any possibility to avoid the warning (but not with suppressWarnings, sry)?

[1137 byte] By [dArignaca] at [2007-10-2 14:41:38]
# 1
I have the same dilema and found this on the net... http://www.developerdotstar.com/mag/articles/troche_factorychain.htmlBasically, they use a new patter to avoid the ugly cast.
seba5618a at 2007-7-13 13:10:51 > top of Java-index,Core,Core APIs...