-2

I want to create a method that can convert a String to an unspecific enum. Here's what I've got so far:

public static Enum<?> toEnum(Class<Enum> targetEnum, String name) {
        return targetEnum.valueOf(targetEnum, name);
}

Something like this...

MyNameIsHans
  • 624
  • 1
  • 7
  • 15

1 Answers1

3

I think you're looking for Enum.valueOf(Class, String), which accepts a Class of some type extending Enum and a String.

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413