public class EnumTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TrafficLamp red = TrafficLamp.RED;
TrafficLamp green = red.nextLamp();
}
public enum TrafficLamp{
RED(30){
public TrafficLamp nextLamp(){
System.out.println(super.time); //此处风景独好,可以参观一下。
System.out.println("red");
return GREEN;
}
},GREEN(30){
public TrafficLamp nextLamp(){
System.out.println("green");
return YELLOW;
}
},YELLOW(5){
public TrafficLamp nextLamp(){
System.out.println("yellow");
return RED;
}
};
private int time;
private TrafficLamp(int time){
this.time = time;
}
public abstract TrafficLamp nextLamp();
}
}
上面是看完张老师的抽象枚举的练习,代码确实很精妙,的确是好代码。
但是看到这样的代码后,我在思考,这样的代码,在实战中哪儿用?
深思中……
|