日期:2014-05-20 浏览次数:20745 次
public enum Lamp {
RED,GREEN,YELLOW;
public Lamp getNext() {
switch (this) {
case RED:
return GREEN;
case GREEN:
return YELLOW;
default:
return null;
}
}
}
Lamp lamp = Lamp.RED;
System.out.println(lamp); //输出:RED
System.out.println(lamp.getNext()); //输出:GREEN
System.out.println(lamp.getNext().getNext()); //输出:YELLOW