Lombok

Lombok ์ด๋ž€?

๊ฐœ๋ฐœํ•  ๋•Œ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ Getter, Setter, ๊ธฐ๋ณธ ์ƒ์„ฑ์ž, toString ๋“ฑ์„ annotation ์œผ๋กœ ์ž๋™ ์ƒ์„ฑํ•ด์ค€๋‹ค

Lombok Annotations

@Getter

Class๋‚ด์— ์„ ์–ธ๋œ ๋ชจ๋“  field์˜ get method๋ฅผ ์ƒ์„ฑํ•ด ์ค€๋‹ค

@RequiredArgsConstructor

  • ์„ ์–ธ๋œ ๋ชจ๋“  final field ๋ฅผ ์ธ์ž๊ฐ’์œผ๋กœ ํ•˜๋Š” ์ƒ์„ฑ์ž๋ฅผ ์ƒ์„ฑํ•ด ์ค€๋‹ค

    • final ์ด ์—†๋Š” field๋Š” ์ƒ์„ฑ์ž์— ํฌํ•จ๋˜์ง€ ์•Š๋Š”๋‹ค

  • ์‚ฌ์šฉํ•˜๋Š” ์ด์œ 

    • ํ•ด๋‹น class์˜ ์˜์กด์„ฑ ๊ด€๊ณ„๊ฐ€ ๋ณ€๊ฒฝ๋  ๋•Œ๋งˆ๋‹ค, ์ƒ์„ฑ์ž ์ฝ”๋“œ๋ฅผ ๊ณ„์†ํ•ด์„œ ์ˆ˜์ •ํ•˜๋Š” ๋ฒˆ๊ฑฐ๋กœ์›€์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•จ

@NoArgsConstructor

  • ๊ธฐ๋ณธ ์ƒ์„ฑ์ž๋ฅผ ์ƒ์„ฑํ•ด ์ค€๋‹ค

  • public Post() {} ์™€ ๊ฐ™์€ ํšจ๊ณผ

@Builder

  • ํ•ด๋‹น Class์˜ Builder pattern class๋ฅผ ์ƒ์„ฑํ•œ๋‹ค

  • Class ์ƒ๋‹จ์— ์„ ์–ธ ์‹œ ์ƒ์„ฑ์ž์— ํฌํ•จ๋œ field๋งŒ builder์— ํฌํ•จ

  • Options

    • toBuilder

      • default = false

      • true๋กœ ์„ค์ • ์‹œ builder๋กœ ๋งŒ๋“  ์ธ์Šคํ„ด์Šค์—์„œ toBuilder() method๋ฅผ ํ˜ธ์ถœํ•ด ๊ทธ ์ธ์Šคํ„ด์Šค ๊ฐ’์„ ๋ฒ ์ด์Šค๋กœ Builder Pattern์œผ๋กœ ์ƒˆ๋กœ์šด ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค

Last updated