I'd like to make a method that implement valueOf on any Enum class passed in parameter (and also wrap some specialized error/missing-name code).
So basically, I have several Enum such as:
enum Enum1{ A, B, C }
enum Enum2{ D, E, F }
And I want a method that wrap around valueOf. I could not find a way to directly pass an Enum class in parameter on which I could call valueOf. Here is what I came up with:
private static Enum getEnum(Class<Enum> E, String name){
for(Enum e: E.getEnumConstants())
if(e.name().equals(name)){
return e;
}
return null;
}
Which I want to call with: getEnum(Enum1,"A"). But it does not like it:
java: cannot find symbol
symbol: variable Enum1
location: class Main
Enum.valueOf(Enum1.class, value);?