wrong target (this) in super default method invocation from an inner class

Peter Levart peter.levart at marand.si
Tue Aug 28 00:23:57 PDT 2012


On Monday, August 27, 2012 12:19:09 PM Dan Smith wrote:
> There is no feature (in the current JSR 335 spec) to refer to a
> superinterface method of an enclosing instance.  The rule for 'Foo.super'
> is that 'Foo' must refer to either a lexically enclosing class name or a
> direct superinterface of the immediately enclosing class.  Otherwise, it's
> an error.

So the below code should actually produce a compile time error.

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