JEP 186: Collection Literals
Millies, Sebastian
Sebastian.Millies at softwareag.com
Tue Jan 14 08:32:32 PST 2014
Yes, one might perhaps want to have new interfaces for immutable/persistent collections. In that case, the correct list implementation (mutable, array-based vs. immutable, tree-based) for the collection literal could be chosen on the basis of the target interface. That would be a definite advantage. -- Sebastian
-----Original Message-----
From: lambda-dev-bounces at openjdk.java.net [mailto:lambda-dev-bounces at openjdk.java.net] On Behalf Of Paul Sandoz
Sent: Tuesday, January 14, 2014 4:46 PM
Cc: lambda-dev at openjdk.java.net
Subject: Re: JEP 186: Collection Literals
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.
Software AG – Sitz/Registered office: Uhlandstraße 12, 64297 Darmstadt, Germany – Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com
More information about the lambda-dev
mailing list