定義系統列舉
阿新 • • 發佈:2020-12-29
package com.zhou.Test; /** * * 系統列舉 * */ public enum StaticCodeEnme { SUCCESS("000","成功"),FAIL("111","失敗"),ERROR("222","錯誤"); private String code; private String desc; //提供一個內部的私有的例項方法 private StaticCodeEnme(String code,String desc){ this.code = code; this.desc = desc; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getDesc() { return desc; } public void setDesc(String desc) { this.desc = desc; } public static String getDescbyCode(String code){ for(StaticCodeEnme codeEnme : StaticCodeEnme.values()){ if(codeEnme.code.equals(code)){ return codeEnme.desc; } } return null; } public static void main(String args[]){ System.out.println(StaticCodeEnme.getDescbyCode("000")); } }