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开发者_JS百科 (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.Level
simply isn't an enum. Did you actually mean that Level
class, or a different one?
The second snippet you posted wouldn't work either, but if you're really talking about the normal Level
class, you can use:
Level level = Level.parse("WARNING");
Level.WARNING
, as well as Level.INFO
and other Loggin levels are no ENUM's.
They're static final
variables in the Level.java
class.
精彩评论