JEP 186: Collection Literals

Howard Lovatt howard.lovatt at gmail.com
Wed Jan 15 17:39:21 PST 2014


It would be interesting to compare which was best for the case of object
literals. Do you have an insight into the pro's and con's?


On 16 January 2014 10:43, Remi Forax <forax at univ-mlv.fr> wrote:

> 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
>
>
>


-- 
  -- Howard.


More information about the lambda-dev mailing list