jeudi 20 février 2020

How to use Lombok @SuperBuilder on Abstract classes with final fields

Given the following classes with the Lombok annotations @Data and @SuperBuilder

@Data
@SuperBuilder
public abstract class Parent {

    protected final String userId;
    protected final Instant requestingTime;
}

@Data
@SuperBuilder
public class Child extends Parent {

    private final Instant beginningDate;
    private final Instant endingDate;
    private final Collection<String> fields;
}

I am getting the following error appearing over the @Data annotation in the Child class:

Implicit super constructor Parent() is undefined. Must explicitly invoke another constructor.

Is there a way to configure a non-default constructor on the Child class's @Data annotation in order to have all final fields on both the Child and Parent classes initialized?

I have tried a few different combinations of the @Data, @Getter, @Setter annotations with the @SuperBuilder annotation on both the child and parent classes, but haven't found a working solution yet. I am using Lombok 1.18.10.

For reference, this question is related

Aucun commentaire:

Enregistrer un commentaire