欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java5新特性(枚举) SUN 

程序员文章站 2024-02-24 07:59:34
...
先来看一下怎么实现枚举类型,下面是模拟枚举类型实现。
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



相关标签: SUN