1、可自定义枚举
public enum WaitStatus { STARTED(0, "等待"), ENDED(1, "进入"), ; private final int value; private final String desc; WaitStatus(int value, String desc) { this.value = value; this.desc = desc; } public int getValue() { return value; } public String getDesc() { return desc; } public static WaitStatus ofValue(Integer target){ for(WaitStatus status : values()){ if(status.value == target){ return status; } } return null; }
调用的话,可灵活。
WaitStatus.ENDED.getValue()
然后可以通过value值去获取description ,很方便