Java基础之枚举类型Emun的使用

·  阅读 490

Java基础之枚举类型Emun的使用

定义
public enum AccruedCleanEnum {


   SPREAD("1","发票"),OTHER("0","收入"),NON_BUSINESS("2","支出");

    private String index;
   private String name;


    AccruedCleanEnum(String index, String name) {
        this.index = index;
        this.name = name;
    }


    public static String getName(String index){

        for(AccruedCleanEnum accruedCleanEnum : AccruedCleanEnum.values()){
            if(accruedCleanEnum.getIndex().equals(index)){
                return accruedCleanEnum.name;
            }
        }
        return "";
    }


    public String getIndex() {
        return index;
    }


    public String getName() {
        return name;
    }

}

复制代码
样例

/**
 * Test <br>
 * 〈〉
 *
 * @author XiaoQiang
 * @create 2019-7-14
 * @since 1.0.0
 */
public class Test {


    @org.junit.Test
    public void Test(){

        AccruedCleanEnum.OTHER.getIndex();//获取键
        AccruedCleanEnum.OTHER.getName(); //获取值
    }
}
复制代码
分类:
后端
标签:
分类:
后端
标签:
收藏成功!
已添加到「」, 点击更改