JEP 186: Collection Literals

Paul Benedict pbenedict at apache.org
Tue Jan 14 07:49:40 PST 2014


Question to Paul Sandoz: collection literals really have no connection to
lambda-dev, right? If that's the case, should all discussion move to
coin-dev or another list?


On Tue, Jan 14, 2014 at 9:46 AM, Paul Sandoz <paul.sandoz at oracle.com> wrote:

>
> On Jan 14, 2014, at 3:34 PM, "Millies, Sebastian" <
> Sebastian.Millies at softwareag.com> wrote:
>
> > I would certainly expect it to be an immutable list, and I believe the
> proposal of having collection literals makes most sense in the context of
> persistent collections. This would be in keeping with evolving Java towards
> a more functional and parallel-friendly programming style, which entails
> embracing immutability. In contrast, what's to be gained from a shorter
> version of Arrays.asList() ?  -- Sebastian
> >
>
> Note that Arrays.asList creates a List implementation that cannot be
> structurally modified; it cannot grow or shrink and is essentially a view
> over the array passed (directly or indirectly) to it. That is why one sees
> annoying code like:
>
>   new ArrayList<>(Arrays.asList(1, 2, 3, 4));
>
> or:
>
>   new ArrayList<Integer>() {{ add(1); add(2); add(3); }};
>
> --
>
> One reason why i pause for thought about immutability is List is not a
> particularly a good interface for an immutable list of elements.
>
> Paul.
>
>
>
>


-- 
Cheers,
Paul


More information about the lambda-dev mailing list