enum 例子

来源:互联网 发布:相声主线知乎 编辑:程序博客网 时间:2024/06/06 18:30
 enum Grade    {        A("100-90"){            String getLocalValue(){                return "优";            }        },        B("89-80")        {            String getLocalValue(){                return "良";            }        },        C("79-70"){            String getLocalValue(){                return "一般";            }        } ,        D("69-60") {            String getLocalValue(){                return "及格";            }        };        private  String score;        Grade(String score) {            this.score = score;}    String getScore()    {        return this.score;    }    abstract String getLocalValue();}public void getGrade(Grade grade)    {        System.out.println(grade.getLocalValue());    }    @Test    public void Test()    {        getGrade(Grade.C);       System.out.println(Grade.A.name() +"::" +Grade.A.ordinal());        Grade g = Grade.valueOf(Grade.class,"B");        System.out.println(g.name());    }
原创粉丝点击