IT/Java
enum 열거형
상짱
2022. 7. 22. 21:10
반응형
- 상수의 열거형이 필요할 경우에 사용한다.
- 간단한 샘플 소스로 내용을 확인하자.
public class EnumTest {
enum test {
OK
, NONE
, NOT_OK
} // end test
enum test2 {
OK {
@Override
public String toString() {
return "000";
}
}
, NONE {
@Override
public String toString() {
return "001";
}
}
, NOT_OK
} // end test2
enum test3 {
OK("OK222")
, NONE("NONE222")
, NOT_OK("NOT_OK222");
private String val;
test2(String val) {
this.val = val;
};
public String getVal(){
return val;
}
} // end test3
public static void main(String...strings) {
System.out.println( test.OK); // OK
System.out.println( test.NONE); // NONE
System.out.println( test.NOT_OK); // NOT_OK
System.out.println( test2.OK); // 000
System.out.println( test2.NONE); // 001
System.out.println( test2.NOT_OK); // NOT_OK
System.out.println( test3.OK); // OK
System.out.println( test3.NONE.val); // NONE222
System.out.println( test3.NOT_OK.getVal()); // NOT_OK222
}
}
반응형