JDK5新特性_2.模擬枚舉類型
阿新 • • 發佈:2018-01-19
turn over class 匿名內部類 nbsp 成了 post ini tostring
/** * 模擬枚舉 * * @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(); }
JDK5新特性_2.模擬枚舉類型