enum MyEnum { ZHANGSAN(1,"zhangsan"), LISI(2, "lisi"), WANGWU(3,"wangwu"); private MyEnum(int age,String name) { this.name = name; this.age = age; } private int age; private String name; public voidsetName(String name) { this.name = name; } public String getName(){ return name; } public void setAge(intage) { this.age = age; } public int getAge() { return age; } } public class Test { public static voiduseEnum(MyEnum enumType) { switch (enumType){ case LISI: System.out.println("LISI的名字是:" + enumType.getName()); return; case WANGWU: System.out.println("WANGWU的名字是:" +MyEnum.WANGWU.getName()); return; default: System.out.println("thisis default"); return; } } public static voidmain(String[] args) { useEnum(MyEnum.LISI); useEnum(MyEnum.WANGWU); useEnum(MyEnum.ZHANGSAN); } } |