What is the output from the following code
enum Level { LOW, MEDIUM, HIGH, URGENT; } public class Main { public static void main(String... args) { Level low1 = Level.valueOf("Low"); // A reverse lookup using a name Level low2 = Level.values()[0]; // A reverse lookup using an ordinal System.out.println(low1); System.out.println(low2); System.out.println(low1 == low2); } }
Exception in thread "main" java.lang.IllegalArgumentException: No enum constant Level.Low at java.lang.Enum.valueOf(Enum.java:238) at Level.valueOf(Main.java:1) at Main.main(Main.java:7)
The reverse lookup for enum constants is case-sensitive.
If you use an invalid constant name with the valueOf() method, an IllegalArgumentException is thrown.