One-sided instantiation (diamond, collection literals)

Neal Gafter neal at
Mon Nov 2 17:26:21 PST 2009


I suspect you're reading more confusion and controversy into this than is
really present.  This is the normal process of language design.  We explore
the corners of a proposed specification until we have it in just the right
shape.  It may take a lot of discussion and tweaking, and it may even
require some hard work from the participants, but that isn't necessarily
because we're finding the basic approach unworkable.

The failure of your proposal to generalize (in the future) to argument
contexts is a killer for me.  The suggested "workaround"

*ArrayList<Widget> widgets(bar, baz);

doesn't work unless the method invocation is a top-level statement or you
don't care about the order of evaluation (try doing this in a base class
constructor invocation).

I'm also not thrilled that you can't declare the variable of an interface
type and initialize it with a class type, and that it looks too much like a
method declaration, but those are secondary.  If you're going to take the
approach that you only get to specify one type, and that the construct only
applies to local variable declarations, I'd rather see a context-sensitive

*var widgets = new ArrayList<Widget>(bar, baz);*

In any case, this is all far too late for project Coin.


More information about the coin-dev mailing list