啥也不说了,直接贴代码~记录一下,方便以后使用。
请执行TestEnum类查看效果~
1.Enum 类Color
/**
*
*/
package hpf.test;
import java.util.EnumMap;
import java.util.EnumSet;
/**
* Enum 类Color
* @author pengfei.hpf
*
*/
public enum Color implements ColorInterface {
/**
* 枚举类型定义,和构造函数相对应
*/
RED("红色", 1),
GREEN("绿色", 2),
BLANK("白色", 3),
YELLOW("黄色", 4);
private String name;
private int index;
/**构造函数
* @param name
* @param index
*/
private Color(String name, int index) {
this.name = name;
this.index = index;
}
/* (non-Javadoc)
* @see hpf.test.ColorInterface#getName()
*/
@Override
public String getName() {
return this.name;
}
/* (non-Javadoc)
* @see hpf.test.ColorInterface#print()
*/
@Override
public String print() {