enum枚举创建实例:
// 以indexNum为顺序进行输出enum中的信息
public enum TestInfoEnum{
infoA("123",1,"Info A MsgA"),
infoB("456",2,"Info B MsgB"),
infoC("789",3,"Info C MsgC");
private String code;
private int indexNum;
private String decode;
private TestInfoEnum(String code, int indexNum, String decode){
this.code = code;
this.indexNum= indexNum;
this.decode= decode;
}
public String getCode(){
return code;
}
public int getIndexNum(){
return indexNum;
}
public String getDecode(){
return decode;
}
}
enum枚举调用实例:
private Map<String,Integer> getTestMapInfo(){
Map<String, integer> resultMap = new HashMap<>();
// enum-->Map
for(TestInfo testInfo : TestInfoEnum.values()){
int index = testInfo.getIndexNum() -1;
resultMap.put(testInfo.getCode(),index);
}
return resultMap;
}
// resultMap进行后续处理