Give this:
Class extends Enum> enumClass = ...; // being passed in from a constructor
Enum e = Enum.valueOf(enumClass, aString); // produces a warnin
Both Enum
and Class
are generic. So if you don't want any warnings:
class Foo>{
Class enumClass;
T e = Enum.valueOf(enumClass, str);
}
Or you can have a generic method:
public > T getEnumValue(Class clazz, String name) {
T e = Enum.valueOf(clazz, name);
return e;
}
But if you don't use generics, you are using raw types, and therefore the compiler issues warnings - there is no option apart from suppressing them.