3

How can I replace the getters in the following example using Lombok?

import lombok.Builder;

public class MyClass {

   private MyBasicDataClass basicData = MyBasicDataClass.builder().myInt(10).myBool(true).build();

   public Integer getMyInt() {
      return basicData.myInt;
   }

   public Boolean getMyBool() {
      return basicData.myBool;
   }

   @Builder
   static class MyBasicDataClass {
      private Integer myInt;
      private Boolean myBool;
   }
}

The basicData property cannot be replaced.

noname
  • 565
  • 6
  • 23
Wiebke
  • 1,006
  • 8
  • 13

1 Answers1

1

This is not possible with Lombok, you have to implement it manually.

You might ask yourself if Lombok could be improved to support such a feature. The answer is: Probably not. In most cases similar to this people want to refer to another (top-level) class, not an inner class. Annotation processors like Lombok do not have access to anything outside the compilation unit they are currently processing. That makes it technically very difficult, probably impossible to implement such a feature in Lombok.

Jan Rieke
  • 7,027
  • 2
  • 20
  • 30