枚举类

作者: 月下饿狼 | 来源:发表于2020-07-07 17:49 被阅读0次

    枚举的写法,mark,自己还没在具体项目中用过

    public enum CountryEnum{
        ONE(1,"齐"),TWO(2,"楚"),THREE(3,"燕"),FOUR(4,"赵"),FIVE(5,"魏"),SIX(6,"韩");
    
        private Integer retCode;
        private String retMessage;
    
        CountryEnum(Integer retCode, String retMessage) {
            this.retCode = retCode;
            this.retMessage = retMessage;
        }
    
        public static CountryEnum CountryEnum_foreach(int index){
            //返回数组
            CountryEnum[] countryEnums = CountryEnum.values();
            for (CountryEnum countryEnum : countryEnums) {
                if(countryEnum.getRetCode() == index){
                    return countryEnum;
                }
            }
            return null;
        }
    
        public Integer getRetCode() {
            return retCode;
        }
    
        public String getRetMessage() {
            return retMessage;
        }
    }
    

    相关文章

      网友评论

          本文标题:枚举类

          本文链接:https://www.haomeiwen.com/subject/yadzqktx.html