Proposal: Collection Literals
Joe Darcy
Joe.Darcy at Sun.COM
Mon Mar 30 20:53:13 PDT 2009
Hi Josh.
A quick comment...
Joshua Bloch wrote:
>
> *AUTHOR: *Joshua Bloch
>
>
> *OVERVIEW*
>
>
> FEATURE SUMMARY: Add support for immutable List, Set, and Map literals, with
> a syntax similar to that of array initializers.
[snip]
> SEMANTICS and COMPILATION: A list literal behaves roughly as if replaced by
> the following "desugaring":
>
>
>
> Arrays. *NonWildTypeArguments**opt* asUnmodifiableList( *
> ElementInitializers* )
>
>
>
> 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:
>
>
> <E> 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.
-Joe
More information about the coin-dev
mailing list