Search code examples
javainheritanceannotationslombokintellij-lombok-plugin

Lombok Annotations are not working with inheritance


I have something like a parent class (File A.java).
Every class is extending this class, as every class needs name.

When I use in File X.java the @With function, it works for the .withDescription("xxx") which is part of File B.java.
But it's not possible to use @With function with .withName("xxx");
At least IntelliJ is not showing .withName("xxx").
But the inherited .setName("xxx") is working as expected.

Any idea how to get this working as expected? I have seen this Answer to use the @SuperBuilder, but I wanted to do it without the @Builer / @SuperBuilder

File A.java

@Getter
@Setter
@With
@MappedSuperclass
public class A {
  public String name;
}

File B.java

@Getter
@Setter
@With
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class B extends A {
  public String description;
}

File X.java

public class X {
  public void x() {
    var b = new B().withDescription("xxx"); // it works
    b.withName("xxx"); // is NOT working.
    b.setName("xxx"); // only set is working, even it's only inherited.
}

Solution

  • You need to add @AllArgsConstructor to A