Skip to content

Builder methods for adding individual items to collection and map properties #100

@cjkent

Description

@cjkent

For example, say we have a bean Foo with a property List<String> names and a map property Map<String, String> attributes.

I'd like to be able to do this:

Foo foo = Foo.builder()
    .addNames("name1")
    .addNames("name2")
    .putAttributes("attr1", "val1")
    .putAttributes("attr2", "val2")
    .build();

This makes for much cleaner code than creating a map or list externally in order to pass it to the builder.

It would be even better if the methods could use the singular, e.g. addName or putAttribute but that's probably a lot to ask and not crucial.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions