daily 2017 7 13 enum枚举类的使用 - wtdig/study GitHub Wiki
1、枚举的values可以获取所有枚举的数据,为一个数组
2、举例:一个item的枚举类,xxx[] items = item.values
代码示例:
枚举类
public enum CoaType {
/**
* 蚂蚁
*/
ANT("蚂蚁集团", "Antfinancial", "50388"),
/**
* 菜鸟
*/
CAINIAO("菜鸟集团", "Cainiao", "50308"),
/**
* 阿里
*/
ALIBABA("阿里巴巴集团", "Alibaba", "50288");
private String enValue;
private String chValue;
private String codeValue;
CoaType(String chValue, String enValue, String codeValue){
this.enValue = enValue;
this.chValue = chValue;
this.codeValue = codeValue;
}
public String getEnValue() {
return enValue;
}
public String getChValue() {
return chValue;
}
public String getCodeValue() {
return codeValue;
}
}
使用枚举:
public List queryCoa() { CoaType[] coas = { CoaType.ANT, CoaType.ALIBABA, CoaType.CAINIAO }; List list = Lists.newArrayListWithCapacity(coas.length); boolean langEN = I18nUtil.isLangEN(); for (int i = 0; i < coas.length; i++) { list.add(new SacComboBoxVo(langEN ? coas[i].getEnValue() : coas[i].getChValue(), coas[i].getCodeValue())); } return list; }