i've got a question about generics. I have this method which does not compile at all. The compiler tells me: type parameter E is not within its bound
. I've usually no problem in understanding compiler errors, but this one is quite tricky. Maybe my knowledge about generics need to improve. :-) Can anyone tell me whats wrong?
public static <E extends Enum & StringConvertableEnum<E>> Map<String, E> map(Class<E> enumClass) {
Map<String, E> mapping = new HashMap<String, E>();
EnumSet<E> set = EnumSet.allOf(enumClass);
for(E enumConstant : set) {
mapping.put(enumConstant.getStringValue(), enumConstant);
}
return mapping;
}
This is the definition of StringConvertableEnum
:
public interface StringConvertableEnum<E extends Enum> {
public E getEnumFromStringValue(String string);
public String getStringValue();
}
You need to change your declaration to E extends Enum<E>
Edit, sorry had to step away, the full declaration I mean is:
public static <E extends Enum<E> & StringConvertableEnum<E>> Map<String, E> map(Class<E> enumClass) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With