Skip to content

Conversation

@junkfactory
Copy link
Owner

If the initial fields in the class are initialized with a collection, the generated builder generates addTo... method.

Given

class Person {
       private final List<Address> addresses = new ArrayList<>();
       private final Set<String> emails;

Generates an inner Builder

public static class Builder {
      private List<Address> addresses = new ArrayList<>();
      private Set<String> emails;

     public Builder addToAddresses(Address e) {
         this.addresses.add(e);
         return this;
     }

    public Builder emails(Set<String> emails) {
        this.emails = emails;
       return this;
    }
}

@junkfactory junkfactory merged commit 97b236f into main Aug 5, 2024
@junkfactory junkfactory deleted the list-members branch August 5, 2024 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants