对枚举的了解一直停留于常量.最近看项目发现如s(-1, "开始"),p(0, "暂停")的用法.学习了一番
此方法属于枚举的常量构造(自己理解的)
public enume Exam{
start(-1, "开始"),pause(0, "暂停");
private int num;
private String desc;
public Exam(int num,String desc){
this.num=num;
this.desc=desc;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
使用时:
Exam[] exams= Exam.values();
for(Exam exam: exams){
//exam.getValue();获取-1
//exam.getDesc());获取开始暂停
}