Effective finality requirements for method reference receiver ?

Dan Smith daniel.smith at oracle.com
Thu Feb 14 09:12:43 PST 2013

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.)

> 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.


> 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-experts mailing list