I have a question about generics. I have this method that does not compile at all. The compiler tells me: type parameter E is not within its bound . Usually I donβt understand the problems with the compiler, but it is rather complicated. Maybe I need to improve my knowledge of generics. :-) Can someone tell me what is 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(); }
java generics
Kraushauslaus
source share