枚举原理Enum
原来方式实现类似枚举 新方法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;
}
}
}
文章来源: bugstack.blog.csdn.net,作者:Yao__Shun__Yu,版权归原作者所有,如需转载,请联系作者。
原文链接:bugstack.blog.csdn.net/article/details/7831576
- 点赞
- 收藏
- 关注作者
评论(0)