Lombok: AllArgsConstructor does not utilize superclass fields

Created on 10 Nov 2016  路  5Comments  路  Source: projectlombok/lombok

If I have a class with AllArgsConstructor and a superclass with AllArgsConstructor. The generated code only populates the current class fields and does not call super class AllArgsConstructor

All 5 comments

Definitely a problem in the current form - if I have inheritance all the super-class fields are effectively hidden.

so the builder of child class also have no fields of super class, i think it should be an issue.

I know that this is very nice to have, however, since getting to the parent class required resolution, it is simply not possible.

@rspilker Has this issue had any development since 2017?

@RuiFernandesCb AFAIK no and AFAIK nothing has changed as when Lombok runs, it can't get enough information about the superclass. What could be done is something like letting the user provide a

@SuperClassStub class Whatever {
    int x;
    int y;
    String name;
}

or (maybe better)

@SuperClassStub abstract void whatever(int x, int y, String name);

which would make Lombok remove the stub, prefix int x, int y, String name, to argument lists of all constructors it generates and generate a super(x, y, name) call therein. This is not very satisfactory because of the field duplication (which has to be kept in sync), but it's not too bad as any mismatch would lead to a compile-time error.

Given the number of upvotes here, it could be better than nothing, WDYT?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pbi-qfs picture pbi-qfs  路  37Comments

lombokissues picture lombokissues  路  42Comments

eximius313 picture eximius313  路  45Comments

pgaschuetz picture pgaschuetz  路  42Comments

xiaolongzuo picture xiaolongzuo  路  32Comments