7 Aralık 2022 Çarşamba

Lombok @With Anotasyonu

Giriş
Şu satırı dahil ederiz
import lombok.With;
Açıklaması şöyle
If we use immutable classes, we can annotate their fields with @With and the equivalent of a setter will be generated. The difference is that the with-er method will return a completely new instance of the object, with one of the fields updated. This annotation can be extremely useful for Java 17’s records
Örnek
Şöyle yaparız
public record User (
  String firstName,
  String lastName,
  Long id,
  @With String email
);

User.withEmail ("...")

Hiç yorum yok:

Yorum Gönder