Help me understand generics. Say I have two enums as inner classes like so:
public class FoodConstants {
public static enum Vegetable {
POTATO,BR
public static <E extends Enum<E>>
String getEnumString(Class<E> clazz, String s){
for(E en : EnumSet.allOf(clazz)){
if(en.name().equalsIgnoreCase(s)){
return en.name();
}
}
return null;
}
The original has a few problems:
EnumSet
does all the reflective stuff for you.