概述
import java.util.HashMap;
import java.util.Map;
public enum TemplateStatusEnum {
STOP(0, "禁用"), ALIVE(1, "启用");
private Integer code;
private String name;
private TemplateStatusEnum(int code, String name) {
this.code = code;
this.name = name;
}
public static Map<Integer, String> code2name = new HashMap<Integer, String>();
static {
for (TemplateStatusEnum status : TemplateStatusEnum.values()) {
code2name.put(status.getCode(), status.getName());
}
}
public Integer getCode() {
return code;
}
public String getName() {
return name;
}
}
____________________________________________________________________________________________
例子二:
package com.suan.basic.constant; import java.util.HashMap; import java.util.Map; /** * 结算方式枚举 * * @author zh * @since 2020-07-27 */ public enum StatementWayConstant { UNITARY(1, "统结"), SELF(2, "自付费"), DEFAULT(null, "默认"); private Integer code; private String meaning; private StatementWayConstant(Integer code, String meaning) { this.code = code; this.meaning = meaning; } public static Map<Integer, String> code2meaning = new HashMap<Integer, String>(); static { for (StatementWayConstant way4Statement : StatementWayConstant.values()) { code2meaning.put(way4Statement.getCode(), way4Statement.getMeaning()); } } public Integer getCode() { return code; } public String getMeaning() { return meaning; } }
最后
以上就是热情服饰为你收集整理的枚举范例代码(原创)的全部内容,希望文章能够帮你解决枚举范例代码(原创)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复