Java

[Effective Java] ์•„์ดํ…œ 62. ๋‹ค๋ฅธ ํƒ€์ž…์ด ์ ์ ˆํ•˜๋‹ค๋ฉด ๋ฌธ์ž์—ด ์‚ฌ์šฉ์„ ํ”ผํ•˜๋ผ.

quedevel 2023. 3. 28. 10:57
728x90
๋ฐ˜์‘ํ˜•

๐ŸŽฏ ์•„์ดํ…œ 62. ๋‹ค๋ฅธ ํƒ€์ž…์ด ์ ์ ˆํ•˜๋‹ค๋ฉด ๋ฌธ์ž์—ด ์‚ฌ์šฉ์„ ํ”ผํ•˜๋ผ.

1๏ธโƒฃ ๋ฌธ์ž์—ด์€ ๋‹ค๋ฅธ ๊ฐ’ ํƒ€์ž…์„ ๋Œ€์‹ ํ•˜๊ธฐ์— ์ ํ•ฉํ•˜์ง€ ์•Š๋‹ค.

๋ฐ›๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์ˆ˜์น˜ํ˜•์ด๋ผ๋ฉด int, float, BigInteger ๋“ฑ ์ ๋‹นํ•œ ์ˆ˜์น˜ ํƒ€์ž…์œผ๋กœ ๋ณ€ํ•œํ•ด์•ผํ•œ๋‹ค.

'์˜ˆ/์•„๋‹ˆ์˜ค' ์งˆ๋ฌธ์˜ ๋‹ต์ด๋ผ๋ฉด ์ ์ ˆํ•œ ์—ด๊ฑฐ ํƒ€์ž…์ด๋‚˜ boolean์œผ๋กœ ๋ณ€ํ™˜ํ•ด์•ผ ํ•œ๋‹ค.

2๏ธโƒฃ ๋ฌธ์ž์—ด์€ ์—ด๊ฑฐ ํƒ€์ž…์„ ๋Œ€์‹ ํ•˜๊ธฐ์— ์ ํ•ฉํ•˜์ง€ ์•Š๋‹ค.

3๏ธโƒฃ ๋ฌธ์ž์—ด์€ ํ˜ผํ•ฉ ํƒ€์ž…์„ ๋Œ€์‹ ํ•˜๊ธฐ์— ์ ํ•ฉํ•˜์ง€ ์•Š๋‹ค.

  • ํ˜ผํ•ฉ ํƒ€์ž…์„ ๋ฌธ์ž์—ด๋กœ ์ฒ˜๋ฆฌํ•œ ๋ถ€์ ์ ˆํ•œ ์˜ˆ
String compoundKey = className + "#" + i.next();

4๏ธโƒฃ ๋ฌธ์ž์—ด์€ ๊ถŒํ•œ์„ ํ‘œํ˜„ํ•˜๊ธฐ์— ์ ํ•ฉํ•˜์ง€ ์•Š๋‹ค.

@Entity
public class Member {
    @Id
    private Long id;

    @Column(name = "name")
    private String username;

    private Integer age;

    @Enumerated(EnumType.ORDINAL)
    private RoleType roleType;
}
public enum RoleType {
    USER, ADMIN;
}

private String roleType ์€ ๊ถŒํ•œ์— ์ ํ•ฉํ•˜์ง€ ์•Š๋‹ค.


์ฐธ๊ณ  ์ž๋ฃŒ

Joshua Bloch, ใ€ŽEffective Java 3/Eใ€, ๊ฐœ์•ž๋งต์‹œ ์˜ฎ๊น€, ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ธ์‚ฌ์ดํŠธ(2018)
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9788966262281&orderClick=LEa&Kc=

728x90
๋ฐ˜์‘ํ˜•