public enum EnumDemoFirst {
RED(1,"hongse"),GREEN(2,"lvse"),YELLOW(3,"huangse");
private int code;
private String msg;
private EnumDemoFirst(int ordinal, String name) {
this.code = ordinal;
this.msg = name;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
测试方法
public class EnumTest {
public static void main(String[] args) {
EnumDemoFirst[] values = EnumDemoFirst.values();
for (EnumDemoFirst enumDemoFirst : values) {
System.out.println(enumDemoFirst + "--" + enumDemoFirst.getCode() + "--" + enumDemoFirst.getMsg());
System.out.println("=============");
}
}
}
输出结果
RED--1--hongse
=============
GREEN--2--lvse
=============
YELLOW--3--huangse
=============