Lombok @Builder doesn't work for inheritance use cases:
For example
class Foo{
protected int xyz1;
.....
protected String xyz7;
}
class Bar extends Foo{
}
For given use case Lombok will not be able to generate methods to set value of parameter defined in Foo class.
A workaround for this is:
Manual creating constructor of Bar.
Putting a Builder annotation on that constructor.
Is there a better workaround ?
解决方案
It´s a bit hidden, but people have had this question before, see:
To summarise the blog post
@AllArgsConstructor
public class Parent {
private String a;
}
public class Child extends Parent {
private String b;
@Builder
private Child(String a, String b){
super(a);
this.b = b;
}
}
Would allow you to use
Child.builder().a("testA").b("testB").build()