Randgalt / record-builder

Record builder generator for Java records

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow subclassing of generated Builder

KangoV opened this issue · comments

I'd like to subclass the generated builder in order to add more quality of life methods, e.g.:

public record Grouping(
    UUID id,
    String name,
    String description,
    String context,
    List<String> objectRefs )  {

    public static class Builder extends GroupingBuilder {
        public Builder id(String id) {
            this.id(UUID.fromString(id));
            return this;
        }
    }

}

Calling any other method on Grouping.Builder other than id(String id) returning a GroupingBuilder not a Grouping.Builder so I don't think this actually very helpful.
The more general way of doing this (because Java does not have a true return self feature) is to parameterize GroupingBuilder<T extends GroupingBuilder> and then have class Builder extends GroupingBuilder<Builder> {}

@Randgalt would you be open to supporting this? I can provide the PR if needed.

@epkugelmass yes, a PR would be welcome but it must be behind an option. It will be complex to get this right as there are already a ton of options to contend with.