public class TestEnum {
public static void main(String[] args) {
System.out.println(getNextLight(TrafficLight.RED));
}
public static TrafficLight getNextLight(TrafficLight currentLight){
switch(currentLight){
case RED:
return currentLight.RED;
case GREEN:
return currentLight.GREEN;
case YELLOW:
return currentLight.YELLOW;
}
return null;
}
}
enum TrafficLight {
RED,GREEN,YELLOW;
} |