-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
Using useInnerClassBuilders, if I have a JSON schema array property that becomes a List Java attribute, the builder class has a withXXX method like this:
public static ApplicationBuilderBase builder() {
return new ApplicationBuilder();
}
public static class ApplicationBuilder extends ApplicationBuilderBase<Application> {
public ApplicationBuilder() {
}
}
public abstract static class ApplicationBuilderBase<T extends Application> {
...
public ApplicationBuilderBase withDeploymentArtifacts(List<DeploymentArtifact> deploymentArtifacts) {
this.instance.deploymentArtifacts = deploymentArtifacts;
return this;
}
But it's difficult to use it without a compiler warning. E.g. this statement:
Application application = Application
.builder()
.withApplicationDescription("x")
.withDeploymentArtifacts(List.of(
DeploymentArtifact
.builder()
.withDeploymentArtifactName("x")
.build(),
DeploymentArtifact
.builder()
.withDeploymentArtifactName("y")
.build()
))
.build();
Emits this compiler warning:
lib/src/main/java/com/User.java:[53,41] unchecked call to withDeploymentArtifacts(java.util.List<DeploymentArtifact>) as a member of the raw type Application.ApplicationBuilderBase
I can use a cast to avoid the warning, but it's pretty awkward to parenthesize correctly, and I think it would stop being readable if you had to add multiple casts for multiple withXXX calls in a row:
Application application = ((Application.ApplicationBuilder)Application
.builder()
.withApplicationDescription("x")) // Here is where you close the parens
.withDeploymentArtifacts(List.of(
DeploymentArtifact
.builder()
.withDeploymentArtifactName("x")
.build(),
DeploymentArtifact
.builder()
.withDeploymentArtifactName("y")
.build()
))
.build();
Any advice is appreciated!
Thanks for the great plugin!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels