JEP 186: Collection Literals

Remi Forax forax at univ-mlv.fr
Wed Jan 15 15:43:49 PST 2014


On 01/16/2014 12:24 AM, Howard Lovatt wrote:
> I don't like limited solutions that are reserved for the language and would
> therefore prefer an exploration of general solutions to the problem. In
> this particular case, won't we be using Streams anyway :). Therefore
> solutions for Lists etc. are past their use by date :).
>
> I think there are two categories for a generic solution, (1) use a static
> factory method or (2) use a builder class. The following example (syntax
> arbitrary) illustrates the issues and relative strengths of the two
> approaches:
>
> IntStream is = {1, 2, 3};
>
> This could be translated using a static factory (1) into:
>
> IntStream is = IntStream.of(1, 2, 3);
>
> Or using a Builder class (2) into:
>
> IntStream is = IntStream.builder().add(1).add(2).add(3).build();

We can also use the Builder Pattern of Ruby now that we have a lambda syntax
   new ArrayList<>(builder -> builder.add(1).add(2).add(3));

Rémi



More information about the lambda-dev mailing list