13 Nisan 2021 Salı

Lombok @UtilityClass Anotasyonu

Giriş
Açıklaması şöyle
@UtilityClass annotation which creates a private constructor that throws an exception, makes the class final, and makes all methods static.
Örnek
Şöyle yaparız
@UtilityClass
// will be made final
public class UtilityClass {
  // will be made static
  private final int GRUBHUB = “ GRUBHUB”;

  // autogenerated by Lombok
  // private UtilityClass() {
  //   throw new java.lang.UnsupportedOperationException("... cannot be instantiated");
  //}

  // will be made static
  public void append(String input) {
    return input + GRUBHUB;
  }
}

Hiç yorum yok:

Yorum Gönder