枚举类
一个标准的枚举类代码
package constants;
public enum Sample {
// 生成成员
s0("s0", 0),
s1("s1", 1);
// 定义字段
private String label;
private Integer value;
// 构造函数
private Sample(String label, Integer value) {
this.label = label;
this.value = value;
}
// 简单的根据value获取label函数,值得注意的是枚举类values的用法
public static String getLabelByValue(Integer value){
for( Sample sample : Sample.values()){
if(sample.value.equals(value)){
return sample.label;
}
}
return null;
}
// 基础的getter
public String getLabel() {
return label;
}
public Integer getValue() {
return value;
}
}