/** * 模拟枚举 * * @author Administrator * */ public abstract class T3_WeekDay { /** * 私有化构造器,防止用户创建对象 */ private T3_WeekDay() { } // 创建两个“枚举”对象 public static final T3_WeekDay SUN = new T3_WeekDay() { /** * 用匿名内部类去重写nextDay方法,将if,else,转移成了一个个独立的类 */ @Override public T3_WeekDay nextDay() { return MON; } public String toString() { return "MON"; }; }; public static final T3_WeekDay MON = new T3_WeekDay() { @Override public T3_WeekDay nextDay() { return SUN; } public String toString() { return "SUN"; }; }; public abstract T3_WeekDay nextDay(); }