JEP 186: Collection Literals
Paul Benedict
pbenedict at apache.org
Tue Jan 14 08:19:36 PST 2014
I think you could likely achieve all those with curly braces. You'll have
the help of type inference during assignment (list vs set) plus you can
nest values whenever you need tuples (maps).
On Tue, Jan 14, 2014 at 10:16 AM, Artur Biesiadowski <abies at adres.pl> wrote:
> Problem is that you need to differentiate list and set (and map possibly).
>
> Few examples from existing languages
>
> Groovy:
>
> List [1,2,3]
> Set [1,2,3] as Set
> Map ["a":1, "b":2]
>
> Xtend
>
> List #[1,2,3]
> Set #{1,2,3}
> Map #{"a"->1, "b"->2}
>
> Scala
>
> List Array(1,2,3)
> Set Set(1,2,3)
> Map Map("a"->1, "b"->2)
>
> C#
>
> List new List<int> {1,2,3}
> Set new HashSet<int> {1,2,3}
> Map new Dictionary<string,int> { {"a":1},{"b":2} }
>
>
>
> Regards,
> Artur Biesiadowski
>
> On 14/01/2014 16:30, Paul Benedict wrote:
> > I would like to see Java have one way of doing initialization with a
> series
> > of values. C11/C++11 decided that curly braces was the way to go. So I
> > would agree with Moshe we should favor curly braces over any new syntax.
> >
> >
> > On Tue, Jan 14, 2014 at 8:34 AM, 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
> >>
> >> -----Original Message-----
> >> From: lambda-dev-bounces at openjdk.java.net [mailto:
> >> lambda-dev-bounces at openjdk.java.net] On Behalf Of Moshe Sayag
> >> Sent: Tuesday, January 14, 2014 2:52 PM
> >> To: lambda-dev at openjdk.java.net
> >> Subject: Re: JEP 186: Collection Literals
> >>
> >> 1. What is the exact meaning of:
> >>
> >> List<Integer> list = #[ 1, 2, 3 ];
> >>
> >> Will 'list' be an ArrayList, a LinkedList or an immutable list?
> >>
> >> 2. Java already has the curly brackets {...} to construct an array.
> >>
> >> int[] array = { 1, 2, 3 };
> >>
> >> How will the new literal go with it?
> >> Will we have:
> >>
> >> int[] array = #[ 1, 2, 3 ];
> >>
> >> What about
> >>
> >> List<Integer> list = { 1, 2, 3 };
> >>
> >>
> >> Moshe
> >>
> >>
> >> On Tue, Jan 14, 2014 at 2:17 AM, <mark.reinhold at oracle.com> wrote:
> >>
> >>> Posted: http://openjdk.java.net/jeps/186
> >>>
> >>> - Mark
> >>>
> >>>
> >>
> >> 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
> >>
> >>
> >>
> >
>
>
>
--
Cheers,
Paul
More information about the lambda-dev
mailing list