映射枚举的定义
enum ColorEnum {
YELLOW("YELLOW", "黄色"),
WHITE("WHITE", "白色"),
GREEN("GREEN", "绿色"),
BLUE("BLUE", "蓝色"),
RED("RED", "红色");
private final String description;
private final String code;
// 每次实例都会调用一次 注意:新增一条数据就会用调用实例,一共五次
ColorEnum(String code, String description) {
System.out.println("编码:" + code + "描述:" + description);
this.code = code;
this.description = description;
}
public String getCode() {
return code;
}
public String getDescription() {
return description;
}
}
场景使用
System.out.println(ColorEnum.YELLOW.getCode());
System.out.println(ColorEnum.YELLOW.getDescription());