M
Mick
Hello, I'm wondering if anyone has ever tried to create an EnumMap
object within a generic, such that the EnumMap keyed based off the
class parameter for that generic. Here is a sample of code that I
thought would logically work for this problem:
START_SNIPPET
public class GenericClass<P extends Enum> {
private Map<P,String> properties;
public GenericClass() {
properties = new EnumMap<P,String>( new HashMap<P,String>() );
// compile error
}
END_SNIPPET
Eclipse points out the following compile error directly on the first
'P' in the marked line of code: "Bound mismatch: The type P is not a
valid substitute for the bounded parameter <K extends Enum<K>> of the
type EnumMap<K,V>"
Does anyone know what I am doing wrong, or perhaps a better way to
accomplish what I am looking for? I realize I could just use a HashMap
for this situation, but I'm curious to know if what I'm attempting is
possible. It seems like it should be possible to use an EnumMap in
this situation.
object within a generic, such that the EnumMap keyed based off the
class parameter for that generic. Here is a sample of code that I
thought would logically work for this problem:
START_SNIPPET
public class GenericClass<P extends Enum> {
private Map<P,String> properties;
public GenericClass() {
properties = new EnumMap<P,String>( new HashMap<P,String>() );
// compile error
}
END_SNIPPET
Eclipse points out the following compile error directly on the first
'P' in the marked line of code: "Bound mismatch: The type P is not a
valid substitute for the bounded parameter <K extends Enum<K>> of the
type EnumMap<K,V>"
Does anyone know what I am doing wrong, or perhaps a better way to
accomplish what I am looking for? I realize I could just use a HashMap
for this situation, but I'm curious to know if what I'm attempting is
possible. It seems like it should be possible to use an EnumMap in
this situation.