20240322_01_EnumClass
定义一个枚举类A
package Enum;
public enum A {
X, Y, Z, BOY, GIRL;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
测试类Test
package Enum;
import javax.swing.*;
public class Test {
public static void main(String[] args) {
A a1 = A.X;
System.out.println(a1);
A a2 = A.Y;
A[] as = A.values();
System.out.println(as[0]);
System.out.println(as[1]);
System.out.println(as[2]);
A a3 = A.valueOf("Z");
System.out.println(a3.name());
System.out.println(a3.ordinal());
System.out.println("===============");
check(A.BOY);
}
public static void check(A sex){
switch (sex){
case BOY:
System.out.println("kkp");
break;
case GIRL:
System.out.println("kkd");
break;
}
}
}