Proposal: Collection Literals (original) (raw)

Joshua Bloch jjb at google.com
Mon Mar 30 21:06:55 PDT 2009


Joe, Thanks for looking at the proposal.

On Mon, Mar 30, 2009 at 8:53 PM, Joe Darcy <Joe.Darcy at sun.com> wrote:

This desugaring assumes the existence of a new library method, asUnmodifiableList, described below under Library Support. Note that type inference of the element type for the list literal is exactly as if the following method were invoked with *ElementInitializers *as as actual parameters:

void foo(E... args) { } So the type of the list is computed as if using var-args, including when the args are themselves augmented constants. One possible wrinkle here is the bad interaction between var-args and generics. This would be removed if only "top level" literals were allowed (i.e. no nested Lists and Set, etc.), at the cost of reducing the utility of the feature.

Good point! Currently, the desugaring of the Pascal's triangle example would work, but it would generate an unchecked generic array creation (of type List<java.lang.Integer>[] for varargs parameter). But, if we end up implementing Bob Lee's proposal ("Simplified Varargs Method Invocation"), the problem goes away:) I consider it a good sign when a group of language changes work well together.

               Josh

P.S. To be fair, I haven't thought through this in gory detail, especially when it comes to map literals. But I'm hopeful.



More information about the coin-dev mailing list