如何实现带抽象方法的枚举,
表示下面的代码没看懂
- public enum TrafficLamp{
- Red(30){//red是一个元素,它是由trafficLamp子类来实现的
- public TrafficLamp nextLamp(){
- return Green;
- }
-
- },
- Green(45){
- public TrafficLamp nextLamp(){
- return Yellow;
- }
- },
- Yellow(5){
- public TrafficLamp nextLamp(){
- return Green;
- }
- };
- public abstract TrafficLamp nextLamp();
-
- private int time;
- private TrafficLamp(int time){
- this.time=time;
- }
-
- }
复制代码 |