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 one of my classes I store a HashMap. The keys for this
HashMap are Strings. The values stored in the HashMap
are the references to any class which implements an interface. (I'll call the interface SomeInterface for this example.) I want the HashMap to be able to store any implementation of the SomeInterface.
Here is my attempt at defining the HashMap using Java Generics:
Eclipse is giving me an error on this statement. It says that it
"Can't instantiate the type HashMap<
String,? extends
SomeInterface>".
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
class that must be extended by all other
implementations of SomeInterface.
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 in advance for the help.
Landon