이상하게 Java의 Enum이 자꾸 헷갈려서 정리함
public enum MyEnum {
A("1"), B("2");
private String value;
MyEnum(String v) {
this.value = v;
}
}
public class EnumTest {
public static void main(String[] args) {
System.out.println("MyEnum.A.toString() : " + MyEnum.A.toString());
System.out.println("MyEnum.A.name() : " + MyEnum.A.name());
System.out.println("MyEnum.A.ordinal() : " + MyEnum.A.ordinal());
System.out.println("MyEnum.valueOf() : " + MyEnum.valueOf("A"));
}
}
결과
MyEnum.A.toString() : A
MyEnum.A.name() : A
MyEnum.A.ordinal() : 0
MyEnum.valueOf() : A