I have two @Data beans in a parent/child relationship. The parent relies on @Data to generate the required constructor. The child declares its own constructor and calls super. When I compile, I get an error in the Child. Error:(6, 1) java: Base() has private access in com.example.Base
This is new in 1.16.22.
// Base.java
@Data
public class Base {
private final String baseProperty;
}
// Child.java
@Data
@EqualsAndHashCode(callSuper = true)
public class Child extends Base {
private final String childProperty;
public Child(String baseProperty, String childProperty) {
super(baseProperty);
this.childProperty = childProperty;
}
}
md5-7a90984c6a546043980eef31dccbdfc8
// build.gradle
plugins {
id 'java'
}
sourceCompatibility = 10
targetCompatibility = 10
repositories {
jcenter()
}
dependencies {
annotationProcessor 'org.projectlombok:lombok:1.16.22'
implementation 'org.projectlombok:lombok:1.16.22'
}
I can work around it if I declare a no-arg constructor in the base class manually and add @RequiredArgsConstructor, but this is ugly because I have to come up with defaults for the final fields.
This could be related to the first feature in changelog: https://projectlombok.org/changelog
Related to Issue #1703
Adding lombok.noArgsConstructor.extraPrivate = false to lombok.config at the root of the project does avoid the issue. This seems like something that should be opt-in though and maybe needs some tuning for better decisions in an inheritance scenario. These classes are not serializable (though that may not matter for the frameworks this was introduced for).
If can also put a @NoArgsConstructor before the @Data like this:
@NoArgsConstructor
@Data
public class Foo {
}
If can also put a
@NoArgsConstructorbefore the@Datalike this:@NoArgsConstructor @Data public class Foo { }
holy。。。。
Most helpful comment
If can also put a
@NoArgsConstructorbefore the@Datalike this: