JEP 186: Collection Literals

Brian Goetz brian.goetz at oracle.com
Wed Jan 15 09:23:41 PST 2014


>> (1) Target-typing means you don't have to redundantly specify T:
>>
>> T v = { e1, ..., en};
>>
>> vs
>>
>> T v = T.of(e1, ..., en);
>>
>> (2) Using the T.of form requires allocating an array,
>> which is then thrown away.
>>
>> I don't think (2) is a major justification. (1) may not
>> be enough to justify a new language feature by itself,
>> though one could argue it's a natural extension of the
>> existing syntax for arrays.
>
> I disagree for (1), if you take a look to java.util.EnumSet by example,
> you will see that there are multiple overloads of 'of' to avoid to allocate
> an array in the common cases.

The multiple overloads are a smell, and its not always trivial to reason 
about what the right set of overloads are.  This is just trading one 
problem (performance) for another (complexity and bloat.)




More information about the lambda-dev mailing list