public enum Opcode {
ESTABLISH(2000, "新增"),
SHUT(2001, "关闭"),
START_USING(2002, "启用");
@Getter
private Integer state;
@Getter
private String descript;
Opcode(Integer state, String descript) {
this.state = state;
this.descript = descript;
}
/**
* 将操作码转换为具体的操作名称
*
* @param code 操作码
* @return 返回操作名称
*/
public static String getNameByopcode(Integer code) {
for (Opcode opcode : Opcode.values()) {
if (opcode.getState().equals(code)) {
return opcode.getDescript();
}
}
return null;
}
public static void main(String[] args) {
System.out.println(getNameByopcode(2000));
}
}
结果: