一、创建枚举类
pulic enum Type{
@Description("零")
zero,
@Description("壹")
one,
@Description("贰")
two
}
pulic enum Type{
TYPE_ZERO(0,"零"),
TYPE_ONE(1,"壹"),
TYPE_TWO(2,"贰")
private Integer type;
private String typeName;
Type(Integer type,String typeName){
this.type = type;
this.typeName = typeName;
}
public void setType(Integer type){
this.type = type;
}
public Integer getType(){
return this.type;
}
public void setTypeName(String typeName){
this.typeName= typeName;
}
public String getTypeName(){
return this.typeName;
}
}
二、常用方法
Type.values()[0].name();
Type.one.ordinal();
Description description = null;
try {
description = Type.class.getField(Type.values()[1].name())
.getAnnotation(Description.class);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
String typeName = description.value();