wrong target (this) in super default method invocation from a lambda
Peter Levart
peter.levart at marand.si
Tue Aug 28 01:28:47 PDT 2012
The following code:
package defaulttest;
public class Outer implements K {
@Override
public void m() {
Runnable r = () -> { K.super.m(); };
r.run();
K.super.m();
}
public static void main(String[] args)
{
new Outer().m();
}
}
in combination with the below interface K also produces the following result:
K.m() this: defaulttest.Outer$1 at 712801c5; Runnable: YES; Outer: NO
K.m() this: defaulttest.Outer at 798c668c; Runnable: NO; Outer: YES
Lambdas are (almost) fully transparent, so this should compile (as opposed to
anonymous inner classes where it is not supported at the moment).
Regards, Peter
On Monday, August 27, 2012 04:30:48 PM Peter Levart wrote:
> While experimenting with current syntax for calling super default methods I
> think I found a bug in b50 compiler. The following example:
>
> package defaulttest;
>
> public interface K {
> void m() default {
> System.out.println(
> "K.m() this: " + this +
> "; Runnable: " + (this instanceof Runnable ? "YES" : "NO") +
> "; Outer: " + (this instanceof Outer ? "YES" : "NO")
> );
> }
> }
>
>
> package defaulttest;
>
> public class Outer implements K {
> @Override
> public void m() {
>
> new Runnable() {
> @Override
> public void run() {
> K.super.m();
> }
> }.run();
>
> K.super.m();
> }
>
> public static void main(String[] args)
> {
> new Outer().m();
> }
> }
>
>
> ...prints the following:
>
> K.m() this: defaulttest.Outer$1 at 798c668c; Runnable: YES; Outer: NO
> K.m() this: defaulttest.Outer at 70a0afab; Runnable: NO; Outer: YES
>
>
> The first line indicates that the K.m() default method is invoked, but with
> the wrong target (this) being the instance of the inner Runnable instead of
> Outer.this ...
>
>
> Regards, Peter
More information about the lambda-dev
mailing list