'1.5'에 해당되는 글 1건

  1. 2007.06.04 | [java] 예약어 enum

[java] 예약어 enum

개발 이야기/Java | 2007. 6. 4. 10:08
Posted by 시반

소스를 정리하다 보니 다음과 같은 Warning이 나오는걸 확인했다.

 

'enum' should not be used as an identifier, since it is a reserved keyword from source level 5.0 on

 

흐음 대충 해석하면 enum은 1.5이상 버젼부터는 예약어로 사용하고 있으니 되도록 사용하지 말것을 권장하고 있다는 것인데...

 

검색해보니 역시 jdk1.5부터 enum 키워드가 추가되었슴을 알게 되었다.

(이궁 그럼 1.5이상으로 변경할 경우 소스 고칠게 많아 지겠군... -_-ㅋ   )

 

enum 키워드는 enumeration 이름과 괄호안으로 들어가야할 가능한 값들을 사용할때 쓰이는데 그 용법은 다음과 같다

enum Color {red, green, blue}

 

예제..


  public class EnumTest {
    public static void main(String args[]) {
      enum Color {red, green, blue};

      // Get collection of values
      System.out.println(Color.VALUES);

      // Check if collection type is java.util.List
      System.out.println(Color.VALUES instanceof java.util.List);

      // Create variable of type
      Color aColor = Color.green;

      // Use enumeration in switch
      switch(aColor) {
        case Color.red:
          System.out.println("Got red.");
          break;
        case Color.green:
          System.out.println("Got green.");
          break;
        case Color.blue:
          System.out.println("Got blue.");
          break;
      }
    }
  }

 

 

 
블로그 이미지

시반

시반(詩伴)이란 함께 시를 짓는 벗이란 뜻을 가지고 있습니다. 함께 나눌수 있는 그런 공간이길 바라며...

카테고리

분류 전체보기 (233)
개발 이야기 (73)
WEB2.0 (57)
DB2 (24)
MySQL (6)
오라클 (26)
기타 (44)
취미 (0)
잡담 (2)