list literal gotcha and suggestion
Reinier Zwitserloot
reinier at zwitserloot.com
Wed Oct 7 18:33:00 PDT 2009
This isn't a fair comparison. You should obviously add any code that
matches the following rough pattern:
List x = new ArrayList<T>();
x.add(expr1);
x.add(expr2);
Also, the very fact that list literals don't exist means people write
code differently. For example, instead of writing a method that'll
accept a list of foos, or accept a list of foos in a constructor, they
may instead have an addFoo() method which adds them one-at-a-time to
the list, even though the most likely usecase boils down to a bunch of
addFoo() calls.
I use ImmutableList/ImmutableMap.of() almost every day.
--Reinier Zwitserloot
On 2009/08/10, at 02:46, Lawrence Kesteloot wrote:
>> http://www.google.com/codesearch?hl=en&lr=&q=ImmutableList.of|
>> ImmutaleSet.of|ImmutableMap.of|Arrays.asList\(\w%2B,\w%2B
>> +lang:java&sbtn=Search
>>
>> Seems like all sorts of configuration/static data/quick and
>> dirty/unittest/mock/etc types of syntax would benefit.
>
> That search returns 800 files out of a total of 11,300,000. That's one
> file in 14,125, or 0.007%.
>
> I would be against a feature which (1) has such an unclear correct
> specification; (2) provides so little advantage over a static
> ArrayList.of() and HashSet.of(); and (3) helps only one file in
> 14,125.
>
> On the other hand, the idea (proposed twice in this discussion) of
> have a pair literal seems much more widely useful, and would allow
> HashMap.of().
>
> Lawrence
>
More information about the coin-dev
mailing list