Give this:
Class<? extends Enum> enumClass = ...; // being passed in from a constructor
Enum e = Enum.valueOf(enumClass, aString); // produces a warning that looks like
[unchecked] unchecked method invocation: valueOf(java.lang.Class,java.lang.String) in java.lang.Enum is applied to (java.lang.Class,java.lang.String)
I don't want to use generics because that's a major change. I don't want to supress. I don't understand why this warning happens. I imagine it is because one cannot extend an Enum type. I get that. But I don't get why the wildcard class is throwing this weird error. Is there a way to fix this without using @SupressWarning
or using generics?
Edit: To Clarify, the following code using generics makes the warning go away.
class Foo<T extends Enum<T>>{
Class<T> enumClass;
Enum e = Enum.valueOf(enumClass, aString);
}
The usage of <T>
is what I mean by using generics. I can't do that because it would be a huge cascading change.