I have few enums like the following:
public enum Season {
SPRING, SUMMER, AUTUM, WINTER
}
public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}
I am trying to write a common method for a concern.
private void doSomethingWithAnyEnum(Class enumClass,String checkThisProperty)
{
if(EnumUtils.isValidEnum(enumClass, checkThisProperty))
{
//here i should be able to call valueOf(String) method on enum
//without bothering about the type coming in.
}
}
So that I can call this method like:
doSomethingWithAnyEnum(Days.class,"blah") ;
doSomethingWithAnyEnum(Seasons.class,"blah");
I am stuck on how to pass a enum and use it's class and name in the method using the same thing. I tried using simpleName() but it doesn't do the job here. Is there a way to do this?