lombok

์ƒ์„ฑ์ผ: 2022๋…„ 6์›” 23์ผ ์˜คํ›„ 4:15

์ฐธ๊ณ  https://projectlombok.org/features/all

Val

  • ํƒ€์ž…์„ ๋ช…์‹œ์ ์œผ๋กœ ์„ ์–ธํ•˜์ง€ ์•Š์•„๋„ ์ž๋™์œผ๋กœ ์žก์•„์คŒ, final ์ด ์ž๋™์œผ๋กœ ์ ์šฉ๋จ

์‚ฌ์šฉํ•œ๊ฒƒ : val example = new ArrayList();

์‚ฌ์šฉ์•ˆํ•œ๊ฒƒ : final ArrayList example = new ArrayList();

Var

  • ์œ„์˜ ๊ธฐ๋Šฅ์—์„œ final ๋งŒ ๋น ์ง

@NonNull

  • Null ์ฒดํฌ ๋กœ์ง์„ ์ž๋™์œผ๋กœ ์ƒ์„ฑํ•ด์คŒ

์‚ฌ์šฉ

import lombok.NonNull;

public class NonNullExample extends Something {
  private String name;
  
  public NonNullExample(@NonNull Person person) {
    super("Hello");
    this.name = person.getName();
  }
}

๋ฏธ์‚ฌ์šฉ

import lombok.NonNull;

public class NonNullExample extends Something {
  private String name;
  
  public NonNullExample(@NonNull Person person) {
    super("Hello");
    if (person == null) {
      throw new NullPointerException("person is marked non-null but is null");
    }
    this.name = person.getName();
  }
}

@NoArgsConstructor

  • ํŒŒ๋ผ๋ฏธํ„ฐ ์—†๋Š” ์ƒ์„ฑ์ž ์ƒ์„ฑ

@RequiredArgsConstructor

  • ์ดˆ๊ธฐํ™” ๋˜์ง€ ์•Š์€ ๋ชจ๋“  final ํ•„๋“œ, @NonNull๋กœ ๋งˆํฌ๋ผ์žˆ๋Š” ๋ชจ๋“  ํ•„๋“œ๋“ค์— ๋Œ€ํ•œ ์ƒ์„ฑ์ž๋ฅผ ์ž๋™์œผ๋กœ ์ƒ์„ฑํ•ด์คŒ

@AllArgsConstructor

  • ํด๋ž˜์Šค์˜ ์กด์žฌํ•˜๋Š” ๋ชจ๋“  ํ•„๋“œ์˜ ์ƒ์„ฑ์ž๋ฅผ ์ƒ์„ฑํ•จ

@Data

  • @Getter / @Setter / @ToString / @RequiredArgsConstructor / @EqualsAndHashCode

  • ์œ„์˜ ์–ด๋…ธํ…Œ์ด์…˜์ด ๋‹ค ์ œ๊ณต๋จ

@Value

  • @Value๋Š” Immutable Class์„ ์ƒ์„ฑํ•ด์ค€๋‹ค. @Data์™€ ๋น„์Šทํ•˜์ง€๋งŒ ๋ชจ๋“  ํ•„๋“œ๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ Private ๋ฐ Final๋กœ ๋กœ ํ•˜๊ณ , Setter ํ•จ์ˆ˜๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ , Class๋˜ํ•œ Final๋กœ ์ง€์ •ํ•˜๋Š” ๊ฒƒ๋งŒ ๋นผ๊ณ  ๋™์ผํ•˜๋‹ค.

@EqualsAndHashCode

  • ์•„๋ž˜ ๋‚ด์šฉ ์ฐธ๊ณ ํ•˜๊ธฐ

equals์™€ hashCode ์‚ฌ์šฉํ•˜๊ธฐ ( +lombok)

@Builder

Lombok @Builder์˜ ๋™์ž‘ ์›๋ฆฌ

[์ž๋ฐ”] ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” Lombok ์–ด๋…ธํ…Œ์ด์…˜

Last updated