Lombok does not support that also indicated by making any @Value
annotated class final
(as you know by using @NonFinal
).
The only workaround I found is to declare all members final yourself and use the @Data
annotation instead. Those subclasses need to be annotated by @EqualsAndHashCode
and need an explicit all args constructor as Lombok doesn't know how to create one using the all args one of the super class:
@Data
public class A {
private final int x;
private final int y;
}
@Data
@EqualsAndHashCode(callSuper = true)
public class B extends A {
private final int z;
public B(int x, int y, int z) {
super(x, y);
this.z = z;
}
}
Especially the constructors of the subclasses make the solution a little untidy for superclasses with many members, sorry.