wrong target (this) in super default method invocation from an inner class
Peter Levart
peter.levart at marand.si
Mon Aug 27 07:30:48 PDT 2012
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