일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- USIM
- 공정위
- HSDPA
- Java
- 라디오
- CDMA
- VoIP
- SWT
- 위피
- 사요
- itmusic
- 러시아
- 민동현의토요명화
- EV-DO Rev. B
- 자바
- 페이스북
- 민동현
- 그녀가말했다
- 김장훈의who
- 모던음악만만세
- Wibro
- 한국의 기획자들
- 차트쇼쇼쇼
- "명탐정 코난"
- 김장훈
- 유희열의라디오천국
- ETF
- 퀄컴
- 이지형
- brew
- Today
- Total
zyint's blog
Java 5.0 Enum 사용 본문
Don't confuse enum with the Enumeration interface, an almost obsolete way of iterating over Collections, replaced by Iterator.
Java 1.5 enums are references to a fixed set of Objects than represent the various possible choices. Enums handle single choices, not combinations of choices. For combinations, you need EnumSet.
Enums and the enum constants are just classes. Normally they should be capitalised. However, since the constant name is the same as what is displayed externally, I gather the capitalisation rules are relaxed. You would name your constants with upper or lower case names as appropriate for the application.
Needless to say, these enums are type safe. If you try to store a code for a dog Breed into a Locomotive type enum variable, the compiler will refuse.
enum Breed {
// the enum constants
Dalmatian ( "spotted" )
, Labrador ( "black" )
, Dachshund( "brown" );
// constructor
Breed ( String colour ) {
this.colour = colour;
}
private String colour;
// additional method of every Breed object
public String getColour() {
return colour;
}
}
-----------------------client 사용
System.out.println( Breed.Dachshund ):