I am begining to believe it is not possible to extend EnumMap
in Java because the super constructor is problematic. A super()
constructor must be called.
I have trialed several variations on the call to super(...)
below. They all give syntax errors.
- Is there a solution that will work as indicated below?
Intented:
abstract public class EnumModel<K extends Enum<K>, T> extends EnumMap<K, T>
{
protected EnumModel( ) {
super( K.class ); // <-- "Cannot select from a type variable"
}
}
For contrast, the example below with a specific Enum type will compile. But only for Enum Colour
.
enum Colour{
RED, BLACK, BLUE;
}
abstract public class EnumModel<T> extends EnumMap<Colour, T>
{
protected EnumModel( ) {
super( Colour.class ); // <-- will compile
}
}