美文网首页
【JAVA】枚举

【JAVA】枚举

作者: 冉小妹Ran | 来源:发表于2019-04-04 14:55 被阅读0次
    package exersice;
    
    import java.util.HashMap;
    import java.util.Map;
    
    public enum HeroType {
        TANK("坦克"),
        WIZARD("法师"),
        ASSASSIN("刺客"),
        ASSIST("辅助"),
        WARRIOR("近战"),
        RANGED("远程"),
        PUSH("推进"),
        FARMING("打野");
        
        private String type;
        static Map<String, HeroType> enumMap= new HashMap<>();
        static {
            for (HeroType heroType : HeroType.values()) {
                enumMap.put(heroType.getChineseName(), heroType);
            }
        }
        
        HeroType(String type) {
            this.type = type;
        }
        
        public static HeroType getHeroType(String chineseName) {
            return enumMap.get(chineseName);
        }
        
        public String getChineseName() {
            return type;
        }
        
        public static void main(String[] args) {
            System.out.println(HeroType.getHeroType("坦克"));
        }
    }
    
    

    相关文章

      网友评论

          本文标题:【JAVA】枚举

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