枚举的使用
/**
*
* 系统枚举
*
*/
enum carEnum{
//无参构造方法
AUDI,BENCHi,BMW
}
public enum StaticCodeEnme {
//带参构造方法
SUCCESS("000","成功"),FAIL("111","失败"),ERROR("222","错误");
private String code;
private String desc;
//提供一个内部的私有的构造方法
private StaticCodeEnme(String code,String desc){
this.code = code;
this.desc = desc;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
//通过状态码获取,状态值
public static String getDescbyCode(String code){
for(StaticCodeEnme codeEnme : StaticCodeEnme.values()){
if(codeEnme.code.equals(code)){
return codeEnme.desc;
}
}
return null;
}
public static void main(String args[]){
//获取方式
System.out.println(StaticCodeEnme.getDescbyCode("000"));
System.out.println(StaticCodeEnme.SUCCESS.getCode());
}
}