本帖最后由 ∏艾力克斯※ 于 2013-11-19 20:47 编辑
- public enum TrafficLamp {
- RED {
- @Override
- public TrafficLamp nextLamp() {
- // TODO Auto-generated method stub
- return GREEN;
- }
- },
- GREEN {
- @Override
- public TrafficLamp nextLamp() {
- // TODO Auto-generated method stub
- return YELLOW;
- }
- },
- YELLOW {
- @Override
- public TrafficLamp nextLamp() {
- // TODO Auto-generated method stub
- return RED;
- }
- };
- // private TrafficLamp() {
- //
- // }
- public abstract TrafficLamp nextLamp();
- private int time;
- private TrafficLamp(int time) {
- this.time = time;
- }
- }
复制代码 以上是一个错误的枚举代码,我想知道的是,为什么我写了
private TrafficLamp(int time) {
this.time = time;
}
以后,上面写好的 RED等枚举就会报错?不太明白其中的机制
|