EFFECTIVE JAVA3 2

EFFECTIVE JAVA3 - 3์žฅ. ๋ชจ๋“  ๊ฐ์ฒด์˜ ๊ณตํ†ต ๋ฉ”์„œ๋“œ

์•„์ดํ…œ 10. equals๋Š” ์ผ๋ฐ˜ ๊ทœ์•ฝ์„ ์ง€์ผœ ์žฌ์ •์˜ํ•˜๋ผ ์ผ๋ฐ˜์ ์œผ๋กœ equals๋ฅผ ์žฌ์ •์˜ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ์ข‹๋‹ค. ๐Ÿ”ธ equals๋ฅผ ์žฌ์ •์˜ ํ•˜์ง€ ์•Š์•„๋„ ๋  ๋•Œ ๊ฐ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋ณธ์งˆ์ ์œผ๋กœ ๊ณ ์œ ํ•  ๋•Œ - Thread ์‹ฑ๊ธ€ํ†ค ์ธ์Šคํ„ด์Šค Enum ๐Ÿ”ธ equals๋ฅผ ์žฌ์ •์˜ ํ•  ๋•Œ ์ง€์ผœ์•ผ ํ•  ๊ทœ์•ฝ (null์ด ์•„๋‹Œ ์ฐธ์กฐ ๊ฐ’) ๋ฐ˜์‚ฌ์„ฑ : x.equals(x)๋Š” true์ด๋‹ค. ๋Œ€์นญ์„ฑ : x.equals(y)๋Š” true์ด๋‹ค. ์ถ”์ด์„ฑ : x.equals(y)๊ฐ€ true์ด๊ณ , y.equals(z)๊ฐ€ true์ด๋ฉด, x.equals(z)๋Š” true์ด๋‹ค. ์ผ๊ด€์„ฑ : x.equals(y)๋ฅผ ๋ฐ˜๋ณตํ•ด์„œ ํ˜ธ์ถœํ•˜๋ฉด ํ•ญ์ƒ ๊ฐ™์€ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. null-์•„๋‹˜ : x.equals(null)์€ false์ด๋‹ค. ๊ตฌ์ฒด ํด๋ž˜์Šค๋ฅผ ํ™•์žฅํ•ด ์ƒˆ๋กœ์šด ๊ฐ’์„ ์ถ”..

EFFECTIVE JAVA3 - 2์žฅ. ๊ฐ์ฒด ์ƒ์„ฑ๊ณผ ํŒŒ๊ดด

EFFECTIVE JAVA3๋ฅผ ์ฝ๊ณ  ๋‚ด์šฉ์„ ์ •๋ฆฌํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค. ์ด๋ฒˆ ์žฅ์€ ๊ฐ์ฒด์˜ ์ƒ์„ฑ๊ณผ ํŒŒ๊ดด๋ฅผ ๋‹ค๋ฃฌ๋‹ค. ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•  ๋•Œ์™€ ๋งŒ๋“ค์ง€ ๋ง์•„์•ผ ํ•  ๋•Œ๋ฅผ ๊ตฌ๋ถ„ํ•˜๋Š” ๋ฒ• ์ œ๋•Œ ํŒŒ๊ดด๋จ์„ ๋ณด์žฅํ•˜๊ณ  ํŒŒ๊ดด ์ „์— ์ˆ˜ํ–‰ํ•ด์•ผ ํ•  ์ •๋ฆฌ ์ž‘์—…์„ ๊ด€๋ฆฌํ•˜๋Š” ์š”๋ น ์•„์ดํ…œ 1. ์ƒ์„ฑ์ž ๋Œ€์‹  ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ๋ฅผ ๊ณ ๋ คํ•˜๋ผ ์—ฌ๊ธฐ์„œ ์–˜๊ธฐํ•˜๋Š” ์ •์  ํŒฉํ„ฐ๋ฆฌ ๋ฉ”์„œ๋“œ๋Š” ๋””์ž์ธ ํŒจํ„ด์˜ ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ์™€ ๋‹ค๋ฅด๋‹ค. ์žฅ์  ๐Ÿ‘ 1. ์ด๋ฆ„์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‹ค. โŒ Bad BigInteger(int, int, Random) โœ… Good BigInteger.probablePrime(int, int, Random) "๊ฐ’์ด ์†Œ์ˆ˜์ธ BigInteger๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค" ๋ผ๋Š” ๋ณด๋‹ค ๋ช…ํ™•ํ•œ ์˜๋ฏธ ์ „๋‹ฌ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.2. ํ˜ธ์ถœ๋  ๋•Œ๋งˆ๋‹ค ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒˆ๋กœ ์ƒ์„ฑํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. ์ด ๋•๋ถ„..