[Java] ์—ด๊ฑฐํ˜•(enum)์ด๋ž€?
ยท
Backend/Java
* ๋ณธ ๋‚ด์šฉ์€ ์„ ์ฐธ๊ณ ํ•˜์—ฌ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค. โ— ์—ด๊ฑฐํ˜•์€ ์—ฌ๋Ÿฌ ์ƒ์ˆ˜๋ฅผ ์„ ์–ธํ•ด์•ผ ํ•  ๋•Œ, ํŽธ๋ฆฌํ•˜๊ฒŒ ์„ ์–ธํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. โ— ์ผ๋ฐ˜์ ์œผ๋กœ ์ƒ์ˆ˜๋ฅผ ์„ ์–ธํ•˜๋Š” ๋ฐฉ๋ฒ• class Card { static final int CLOVER = 0; static final int HEART = 1; static final int DIAMOND = 2; static final int SPADE = 3; final int kind; } โ— ์—ด๊ฑฐํ˜•์„ ์ด์šฉํ•˜์—ฌ ์ƒ์ˆ˜๋ฅผ ์„ ์–ธํ•˜๋Š” ๋ฐฉ๋ฒ• class Card { enum Kind { CLOVER, HEART, DIAMOND, SPADE } final Kind kind; } ๋”ฐ๋กœ ๊ฐ’์„ ์ง€์ •ํ•ด์ฃผ์ง€ ์•Š์•„๋„ ์ž๋™์ ์œผ๋กœ 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” ์ •์ˆ˜๊ฐ’์ด ํ• ๋‹น๋œ๋‹ค. ์—ด๊ฑฐํ˜•์„ ์ •์˜ํ•˜๋Š” ๋ฐฉ๋ฒ• - enum ์—ด๊ฑฐ..
_์„ฑํ˜ธ_
'์—ด๊ฑฐํ˜•' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก