Constructor references
Rémi Forax
forax at univ-mlv.fr
Fri Jul 16 03:08:55 PDT 2010
Le 16/07/2010 11:46, Stephen Colebourne a écrit :
> On 16 July 2010 08:31, Fredrik Ohrstrom<oehrstroem at gmail.com> wrote:
>
>> Yes, however it is not quite a normal method reference because the
>> constructor does not allocate so you want the constructor prefixed
>> with an alloc.
>>
> Well, I'd simply make the constructor reference do the allocation.
> Thats the most expected behaviour.
>
Agree, that why the syntax should contains 'new'.
The fact you need 3 instruction to do an allocation is a VM language quirk
not a part of Java the language story.
By the way, John (and I agree with him) already propose a syntax
for constructor reference.
see method testConstructors() in
http://hg.openjdk.java.net/mlvm/mlvm/langtools/file/5fd2ac635231/meth-ldc-6939203.patch
the proposed syntax is
#new String(String)
or
outer#new Inner()
for a non static inner class.
>
>> To do that new code has to be created, so why not
>> go with a lambda?
>> { name, age -> new Person(name, age) }
>>
> Same argument applies to method references. They are being added
> because they are a common and useful convenience.
>
> Stephen
>
>
Rémi
More information about the lambda-dev
mailing list