Effective finality requirements for method reference receiver ?
Remi Forax
forax at univ-mlv.fr
Thu Feb 14 12:16:15 PST 2013
On 02/14/2013 06:12 PM, Dan Smith wrote:
> On Feb 13, 2013, at 9:41 PM, Srikanth S Adayapalam <srikanth_sankaran at in.ibm.com> wrote:
>
>> Are there any ?
>>
>> 0.6.1 - Part C is silent. The words final and capture don't occur there.
>> But SOTL 4th edition talks about the implicit lambda capturing a variable
>> and using that as the receiver. Spec should override all other prose - right ?
>> I also see that the mention of implicit lambda is from a pedagogical pov.
> Here's the relevant spec, from Part E, 15.28.2:
>
> "If the method reference begins with an ExpressionName or a Primary, the target reference of the invocation is the value of this expression, as determined _at the time_ the method reference was evaluated, and the parameters of the invocation are the parameters of the synthetic method."
>
> The intuition is that "Func f = expr::foo;" is translated into something like this:
>
> final Foo receiver = expr;
> Func f = (x, y) -> receiver.foo(x, y);
>
> (Hard to actually do such a translation in general, though, since you can't put variable declarations in the middle of an expression.)
FYI, javac has a special node for doing this exact translation
internally (line 2374 of [1]) but it doesn't use it in that case.
>> BTW, 0.6.1 Part B links to SOTL edition 3 - which is very outdated with respect
>> to the present state of affairs.
> Thanks. I'll fix that.
>
> —Dan
Rémi
[1]
http://hg.openjdk.java.net/lambda/lambda/langtools/file/dae2aede7f35/src/share/classes/com/sun/tools/javac/tree/JCTree.java
>
>> I see that javac 8b74 compiles this code fine:
>>
>> // --
>> interface I {
>> void foo();
>> }
>>
>> public class X {
>> private void foo() {
>> X x = new X();
>> x = new X();
>> I i = x::foo;
>> }
>> }
>>
>> Thanks in advance for any clarifications.
>> Srikanth.
More information about the lambda-spec-observers
mailing list