package com.ethan.enumtest;
//手工实现枚举类
public abstract class WeekDay1 {
//私有构造方法
private WeekDay1(){};
/*public final static WeekDay SUN = new WeekDay();
public final static WeekDay MON = new WeekDay();*/
/*将if else 转为 独立的类
* public WeekDay nextDay() {
if(this==SUN) {
return MON;
} else {
return SUN;
}
}*/
public abstract WeekDay1 nextDay();
//匿名内部类,实现抽象类
public final static WeekDay1 SUN = new WeekDay1() {
@Override
public WeekDay1 nextDay() {
return MON;
}
};
public final static WeekDay1 MON = new WeekDay1() {
@Override
public WeekDay1 nextDay() {
return SUN;
}
};
public String toString() {
return this==SUN?"SUN":"MON";
}
}
package com.ethan.enumtest;//手工实现枚举类public abstract class WeekDay1 { //私有构造方法 private WeekDay1(){}; /*public final static WeekDay SUN = new WeekDay(); public final static WeekDay MON = new W