Notice
Recent Posts
Recent Comments
ยซ   2024/12   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
Archives
Today
In Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

A Joyful AI Research Journey๐ŸŒณ๐Ÿ˜Š

Java: Lombok์˜ ์–ด๋…ธํ…Œ์ด์…˜ ๋ณธ๋ฌธ

๐Ÿ’ปBootcamp Self-Study Revisionโœจ/Spring, Spring Boot, Java, SQL

Java: Lombok์˜ ์–ด๋…ธํ…Œ์ด์…˜

yjyuwisely 2023. 4. 10. 14:36

๋กฌ๋ณต(lombok)์€ ์ž๋ฐ” ํด๋ž˜์Šค์— Getter, Setter, ์ƒ์„ฑ์ž ๋“ฑ์„ ์ž๋™์œผ๋กœ ๋งŒ๋“ค์–ด ์ฃผ๋Š” ๋„๊ตฌ์ด๋‹ค.


Lombok ์˜ ์–ด๋…ธํ…Œ์ด์…˜

์–ด๋…ธํ…Œ์ด์…˜ ์„ค๋ช…
@NonNull  Null ๊ฐ’์ด ๋  ์ˆ˜ ์—†๋‹ค๋Š” ๊ฒƒ์„ ๋ช…์‹œ
@Cleanup ์ž๋™์œผ๋กœ close() ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœ
@Getter/Setter ์ฝ”๋“œ๊ฐ€ ์ปดํŒŒ์ผ๋  ๋•Œ ์†์„ฑ๋“ค์— ๋Œ€ํ•ด์„œ Getter/Setter ๋ฉ”์†Œ๋“œ๋“ค์„ ์ƒ์„ฑ
@ToString toString() ๋ฉ”์†Œ๋“œ๋ฅผ ์ƒ์„ฑ
@EqualsAndHashCode ํ•ด๋‹น ๊ฐ์ฒด์˜ equals() ์™€ hashCode() ๋ฉ”์†Œ๋“œ๋ฅผ ์ƒ์„ฑ
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฐ›์ง€ ์•Š๋Š” ์ƒ์„ฑ์ž๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๊ฑฐ๋‚˜(@NoArgsConstructor),
์ง€์ •๋œ ์†์„ฑ๋“ค์— ๋Œ€ํ•ด์„œ๋งŒ ์ƒ์„ฑ์ž๋ฅผ ๋งŒ๋“ค๊ฑฐ๋‚˜(@RequiredArgsConstructor),
๋ชจ๋“  ์†์„ฑ๋“ค์— ๋Œ€ํ•ด์„œ ์ƒ์„ฑ์ž๋ฅผ ๋งŒ๋“ ๋‹ค(@AllArgsConstructor)
@Data @ToString,
@EqualsAndHashCode,
@Getter(๋ชจ๋“  ์†์„ฑ),
@Setter(final ์ด ์•„๋‹Œ ์†์„ฑ),
@RequiredArgsConstructor๋ฅผ ํ•ฉ์ณ๋‘” ์–ด๋Šํ…Œ์ด์…˜
@Value ๋ถˆ๋ณ€ ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑ
@Log ์ž๋™์œผ๋กœ ์ƒ๊ธฐ๋Š” log ๋ผ๋Š” ๋ณ€์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ๋กœ๊ทธ๋ฅผ ์ฐ์„ ์ˆ˜ ์žˆ์Œ
@Builder ๋นŒ๋” ํŒจํ„ด์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ฝ”๋“œ๋ฅผ ์ƒ์„ฑ. new AA().setA().setB().setC() ์™€ ๊ฐ™์ด ์ฒด์ด๋‹์„ ํ•  ์ˆ˜ ์žˆ๋Š” ์ฝ”๋“œ๋ฅผ ์ƒ์„ฑ
@SneakyThrows ์˜ˆ์™ธ ๋ฐœ์ƒ ์‹œ Throwable ํƒ€์ž…์œผ๋กœ ๋ฐ˜ํ™˜
@Synchronized ๋ฉ”์†Œ๋“œ์—์„œ ๋™๊ธฐํ™”๋ฅผ ์„ค์ •
@Getter(lazy=true) ๋™๊ธฐํ™”๋ฅผ ์ด์šฉํ•ด์„œ ์ตœ์ดˆ ํ•œ ๋ฒˆ๋งŒ getter๋ฅผ ํ˜ธ์ถœ

์ฐธ๊ณ : https://yunyoung1819.tistory.com/95


728x90
๋ฐ˜์‘ํ˜•
Comments