We would like to know how to use enum inside a switch.
//from w w w.j ava 2 s. co m enum Color { BLUE, RED, YELLOW }; public class Main { public static void main(String[] args) { Color c = Color.BLUE; switch (c) { case BLUE: System.out.println("Blue!"); break; case RED: System.out.println("Red!"); break; case YELLOW: System.out.println("Yellow!"); break; default: System.out.println("Logic error!"); } } }
The code above generates the following result.