Skip to content

A way to avoid redundant type parameters for ImmutableMap.builder() #883

Closed
@gissuebot

Description

@gissuebot

Original issue created by drothmaler on 2012-01-25 at 03:13 PM


When building immutalbe maps/lists you allways have the problem, that you will have respecify the element type, with the builder method.

So you end up writing things like:

public static final ImmutableMap<String, String> STRINGS = ImmutableMap.<String, String> builder()
        .put("A", "Foo")
        .put("B", "Foo")
        .put("C", "Foo")
        .build();

If you had a "builder" method, that takes the first value(-pair) you could write:

public static final ImmutableMap<String, String> STRINGS =
    ImmutableMap
        .builder("A", "Foo")
        .put("B", "Foo")
        .put("C", "Foo")
        .build();

It also could be named "put" instead.

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