package enumTest; public enum BaseServiceEnum { /** * 旗舰版 */ ULTIMATE_SERVICE("1","ultimateAndGPUService"), /** * GPU版 */ GPU_SERVICE("2","ultimateAndGPUService"), /** * 普通版 */ NORMAL_SERVICE("3","NormalService"), /** * 专属版 * */ EXCLUSIVE_SERVICE("4","ExclusiveService"); /** * 桌面类型 */ private String categoryCode; /** * 业务serivce名称 */ private String serviceName; public String getCategoryCode() { return categoryCode; } public void setCategoryCode(String categoryCode) { this.categoryCode = categoryCode; } public String getServiceName() { return serviceName; } public void setServiceName(String serviceName) { this.serviceName = serviceName; } private BaseServiceEnum(String categoryCode, String serviceName) { this.categoryCode = categoryCode; this.serviceName = serviceName; } /** * 根据code值获取名称 */ public static String getServiceName(String code) { for(BaseServiceEnum enu:BaseServiceEnum.values()) { if(code.equals(enu.categoryCode)) { return enu.serviceName; } } return null; } }
//测试类
package enumTest; public class TestEnum { public static void main(String[] args) { String code=BaseServiceEnum.EXCLUSIVE_SERVICE.getCategoryCode(); System.out.println("code==="+code); String name=BaseServiceEnum.getServiceName("2"); System.out.println("name===="+name); } }