1、简单使用,添加普通方法,重写父类方法
public enum Color {
RED("红色",1),
GREEN("绿色",2),
YELLOW("黄色",3);
private String des;
private int code;
Color(String des , int code){
this.des = des;
this.code = code;
}
public String getDes(){
return des;
}
public int getCode(){
return code;
}
public static String getDesByCode(int code){
for (Color color : Color.values()) {
if(color.getCode() == code){
return color.getDes();
}
}
return null;
}
@Override
public String toString(){
return this.des+"-"+ this.code;
}
}