JEP 186: Collection Literals

Per Bothner per at bothner.com
Wed Jan 15 09:28:13 PST 2014


On 01/15/2014 09:14 AM, Remi Forax wrote:
> On 01/15/2014 06:04 PM, Per Bothner wrote:
>> (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 disagree for (1),

You mean (2), presumably.

> 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.

For EnumSet, the short cases are probably the common cases.
That doesn't help for lists that are longer than some small number.

However, I don't consider this a major motivation.  If performance
is a factor, it should be possible for the VM to special-case
the argument-passing.  Certainly for common well-known classes.
-- 
	--Per Bothner
per at bothner.com   http://per.bothner.com/


More information about the lambda-dev mailing list