일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- Wibro
- VoIP
- 위피
- 민동현
- 차트쇼쇼쇼
- 사요
- brew
- 유희열의라디오천국
- 이지형
- 공정위
- HSDPA
- 자바
- 모던음악만만세
- "명탐정 코난"
- SWT
- 그녀가말했다
- 러시아
- 한국의 기획자들
- CDMA
- ETF
- 김장훈
- 라디오
- 퀄컴
- 페이스북
- EV-DO Rev. B
- 민동현의토요명화
- USIM
- itmusic
- Java
- 김장훈의who
- 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 ):