Currently I have these three classes:
@Value
@NonFinal
@SuperBuilder
public class Parent {
// Some fields
}
@Value
@EqualsAndHashCode(callSuper = true)
@SuperBuilder(toBuilder = true)
public class ChildA extends Parent {
// Some fields
}
@Value
@EqualsAndHashCode(callSuper = true)
@SuperBuilder(toBuilder = true)
public class ChildB extends Parent {
// Some fields
}
I want to use it in a mapper as follows to avoid duplicating any code:
private ChildA buildChildA(Entity entity) {
Parent parent = ((ChildB) buildParent(entity, ChildA.builder().build()))
.toBuilder()
// Populate Child A fields from entity
.build();
}
private ChildB buildChildB(Entity entity) {
Parent parent = ((ChildA) buildParent(entity, ChildA.builder().build()))
.toBuilder()
// Populate Child B fields from entity
.build();
}
private Parent buildParent(Partner entity, Parent parent) {
return parent.toBuilder()
// Populate Parent fields here
.build();
}
However when I try to compile I get:
ChildA.java:13: error: method does not override or implement a method from a supertype
@SuperBuilder(toBuilder = true)
^
ChildB.java:13: error: method does not override or implement a method from a supertype
@SuperBuilder(toBuilder = true)
^
2 errors
How do you use toBuilder with @SuperBuilder? I'm using lombok v1.18.4.