Proposal: Collection Literals (original) (raw)
Joe Darcy Joe.Darcy at Sun.COM
Mon Mar 30 20:53:13 PDT 2009
- Previous message: Proposal: Collection Literals
- Next message: Proposal: Collection Literals
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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: 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
- Previous message: Proposal: Collection Literals
- Next message: Proposal: Collection Literals
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]