I was hoping you guys might be able to give me a little help with Java
Generics. I'm trying to track down a null pointer exception in my
pluggable rendering code, and I think it may result from improper use
of Generics.

In my RenderingFactory class I store a HashMap. The keys for this
HashMap are Strings representing the fully qualified class name of the
IRendererFactoryTool implementation. The values stored in the HashMap
are the references to the RendererFactoryTools. I need this collection
to store any implementation of the IRendererFactoryTool interface.

Here is my attempt at defining the HashMap using Java Generics:

private HashMap<String, ? extends IRendererFactoryTool>
rendererFactoryTools = new HashMap<String,? extends
IRendererFactoryTool>();

Eclipse is giving me an error on this statement. It says that it
"Can't instantiate the type HashMap<String,? extends
IRendererFactoryTool>".

I'm guessing this is becuase I'm trying to use an interface and not a
class as the upper bound of my wild card in the generics declaration.
Is there a way around this, other than defining a default
RendererFactoryTool class that must be extended by all other
implementations of the IRendererFactoryTool interface.

I'm really surprised that you can't use interfaces in this type of
statement. Unless of course, I've got another mistake staring me in
the face.

Thanks for the help. i'll find that null pointer exception if it kills me. :]

The Sunburned Surveyor

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to