Proposal: Collection Literals

Joshua Bloch jjb at google.com
Tue Mar 31 01:19:38 PDT 2009


Vilya,
Hi.  I originally felt the same way, and so drafted the proposal with curly
braces for list literals (which are almost like arrays) and square brackets
for maps.  But this was the opposite of what people are used to from other
languages such as Python, Perl, JavaScript, and Ruby.  On balance, it was
even more confusing so I opted for the proposed syntax.  There's no actual
ambiguity, as a bare array initializer (without the new Foo[]) is only legal
on the right side of an array declaration.

                 Regards,

                 Josh

On Tue, Mar 31, 2009 at 12:56 AM, Vilya Harvey <vilya.harvey at gmail.com>wrote:

> Hi Josh,
>
> This would be a very nice feature to have. One small nit:
>
> By substituting curly braces for the square brackets, you get a set literal
>> in place of a list:
>>
>>
>>   final Set<Integer> primes = { 2, 7, 31, 127, 8191, 131071, 524287 };
>>
>
> The literal syntax is the same as for an array initialisation, which could
> cause a bit of confusion. In the example - for example :-) - it looks like
> an array of ints is being autoboxed into a set., but I presume that won't
> actually be what happens (i.e. the assignment wouldn't compile if the
> literal was replaced by a variable with type int[])?
>
> Vil
>



More information about the coin-dev mailing list