原来方式实现类似枚举 新方法enum对照
public abstract class WeekDay{ public class EnumAbstract{
private WeekDay(){} public static void main(String[] args){
TrafficLamp tl = TrafficLamp.RED;
public abstract WeekDay nextDay(); System.out.println(tl);
public final static WeekDay SUN = new WeekDay(){ }
public WeekDay nextDay(){ public enum TrafficLamp{
return MON; RED(30){
} public TrafficLamp nextLamp(){
}; return GREEN;
public final static WeekDay MON = new WeekDay(){ }
public WeekDay nextDay(){ },GREEN(45){
return SUN; public TrafficLamp nextLamp(){
} return YELLOW;
}; }
},YELLOW(5){
public String toString(){ public TrafficLamp nextLamp(){
return this==SUN?"SUN":"MON"; return RED;
} }
} };
public abstract TrafficLamp nextLamp();
private int time;
private TrafficLamp(int time){
this.time = time;
}
}
}