I’m trying to derive an enum value from a String, like:
Level level = Enum.valueOf(Level.class, "WARNING");
But all I get is compiler warnings like:
Test.java:8: <T>valueOf(java.lang.Class<T>,java.lang.String) in java.lang.Enum cannot be applied to (java.lang.Class<java.util.logging.Level>,java.lang.String)
I know in JDK versions prior to 1.5 this:
Level level = Level.valueOf("WARNING");
would work, but I’m using JDK 1.6. Could anyone provide a working example for this kind of problem?
Thanks.
java.util.logging.Levelsimply isn’t an enum. Did you actually mean thatLevelclass, or a different one?The second snippet you posted wouldn’t work either, but if you’re really talking about the normal
Levelclass, you can use: