I'm trying to set up cloning with Lombok using its @With annotation, but I ran into a problem where it sets inherited fields to null. To demonstrate, say I have the following class hierarchy:
@NoArgsConstructor
@AllArgsConstructor
@Getter
abstract class Person {
protected String name;
protected Integer age;
}
@NoArgsConstructor
@AllArgsConstructor
@With
@Getter
class Employee extends Person {
protected String id;
@Builder
public Employee(String name, Integer age, String id) {
super(name, age);
this.id = id;
}
}
When I try doing:
var template = Employee.builder().name("John Smith").age(20).build();
var clone = template.withId("ABC123");
both clone.name and clone.age return null. Is this construct allowed? How do I make it work?