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 > Map map(Class enumClass) {
Map mapping = new HashMap();
EnumSet set = EnumSet.allOf(enumClass);
for(E enumConstant : set) {
mapping.put(enumConstant.getStringValue(), enumConstant);
}
return mapping;
}
This is the definition of StringConvertableEnum:
public interface StringConvertableEnum {
public E getEnumFromStringValue(String string);
public String getStringValue();
}
解决方案
You need to change your declaration to E extends Enum
Edit, sorry had to step away, the full declaration I mean is:
public static & StringConvertableEnum> Map map(Class enumClass) {