Java5新特性(枚举) SUN
程序员文章站
2024-02-24 08:48:42
...
先来看一下怎么实现枚举类型,下面是模拟枚举类型实现。
全文请访问:http://www.juziku.com/wiki/229.htm
package com.juziku; /** * 模拟枚举类型 * @author sunlightcs * 2011-3-3 * http://hi.juziku.com/sunlightcs/ */ public abstract class WeekDay { private WeekDay(){} public final static WeekDay SUN = new WeekDay(){ @Override public WeekDay nextDay() { return MON; } }; public final static WeekDay MON = new WeekDay(){ @Override public WeekDay nextDay() { return SUN; } }; public abstract WeekDay nextDay(); public String toString(){ return this == SUN ? "SUN" : "MON"; } } package com.juziku; /** * 枚举类型测试类 * @author sunlightcs * 2011-3-3 * http://hi.juziku.com/sunlightcs/ */ public class EnumTest { public static void main(String[] args) { System.out.println(WeekDay.MON); System.out.println(WeekDay.MON.nextDay()); } }
全文请访问:http://www.juziku.com/wiki/229.htm