Open
Description
When trying to build a concrete schema using it's builder I met a strange situation when methods calling order matters because of their return types.
For example this code is valid:
StringSchema stringValue = StringSchema.builder()
.maxLength(10)
.title("String value")
.build();
while this is not:
StringSchema stringValue = StringSchema.builder()
.title("String value")
.maxLength(10)
.build();
This feels like a bug to me.
One of the possible solutions is to use a concrete builder as a generic parameter:
public abstract class Schema {
public abstract static class Builder<S extends Schema, B extends Builder> {
public B title(String title) {
this.title = title;
//noinspection unchecked
return (B) this;
}
}
}
public class StringSchema extends Schema {
public static class Builder extends Schema.Builder<StringSchema, Builder> {
}
}
Metadata
Metadata
Assignees
Labels
No labels