i have a method:
public Object instantiateAlmostAnyType(String stringToParse, Class<?> targetType) {
...
if (targetType.isEnum())
return Enum.valueOf((Class)targetType, stringToParse);
}
it works but i got compiler warnings. all for the return line:
Class is a raw type. References to generic type Class should be parameterized Enum is a raw type. References to generic type Enum should be parameterized Type safety: The expression of type Class needs unchecked conversion to conform to Class Type safety: Unchecked invocation valueOf(Class, String) of the generic method valueOf(Class, String) of type Enum
is there any way (except @suppressWarnings) to avoid warnings? any casts?
till now i haven’t found a solution so i assume it’s impossible. if someone gives me the answer i will accept it