list literal gotcha and suggestion

Lawrence Kesteloot lk at
Wed Oct 7 19:23:14 PDT 2009

Okay, I'll be generous and stipulate that I've underestimated it by a
factor of 100. That's still only 0.7% of files in that code base. It's
nowhere near, for example, foreach, which probably appears in a
majority of files written since 1.5.

No matter what syntax we choose for this, you can already hear the
zillions of blog posts: "I can't believe they chose that ridiculous
syntax for list literals. It trips me up every time I use it."

Java has never been about conciseness. It has always preferred
verbosity for things that are infrequent, and I count 1% of files as
infrequent. Combine that with the lack of clarity in design, and
you've got a solid candidate for "when in doubt, leave it out."


On Wed, Oct 7, 2009 at 6:33 PM, Reinier Zwitserloot
<reinier at> wrote:
> 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:
> 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