JEP 186: Collection Literals
Remi Forax
forax at univ-mlv.fr
Tue Jan 14 14:34:08 PST 2014
On 01/14/2014 06:02 PM, Brian Goetz wrote:
> And, we have now reached our quota of syntax discussion on this topic.
> No more, please! Such discussions get in the way of the important
> questions like:
[...]
> - how does this map to bytecode
We need new constant pool entries for arrays (like MSIL does), it's
currently possible to encode arrays as a String (by example by
uuencoding the values) but it's awkward.
Then a collection literal can be encoded using invokedynamic.
By example,
int a = ...
{ 1, 2, a} as ArrayList (or any other syntax :)
or
{ "foo": 2, "bar": a } as HashMap
can be encoded like this:
iload 'a'
invokedynamic (int)ArrayList
or
iload 'a'
invokedynamic (int)HashMap
Because Collection and Map are two different interfaces,
we need two different bootstrap method.
For a Collection:
- a reference to the array
- an array of the position of the placeholder (where to insert 'a' in
the example)
- a methodhandle on the method used to create the builder
- a method handle on the method used to append a value
- a method hande to transform the builder to a Collection
and for a Map, you need a supplementary array
(one for the keys and one for the values).
cheers,
Rémi
More information about the lambda-dev
mailing list