javac bug: dispatch to multiply inherited defenders

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Oct 28 04:16:52 PDT 2010


On 28/10/10 04:04, Brian Goetz wrote:
> class MultipleInheritanceTest extends DefenderTestCase {
>       private interface A {
>           public extension int get() default Implementations.one;
>       }
>
>       private interface B {
>           public extension int get() default Implementations.one;
>       }
>
>       private static class X implements A, B { }
>
>       public void testValidMI() {
>           assertDefender(X.class, "get", new Class[] { },
> Implementations.class, "one");
>           X x = new X();
>           assertEquals(1, x.get());        // @@@
>           assertEquals(1, ((A) x).get());
>           assertEquals(1, ((B) x).get());
>       }
> }
>    
Not sure about this one - if Implementations defines two methods like:

class Implementations {
    static int one(MultipleInheritanceTest.A a) { ... }
    static int one(MultipleInheritanceTest.B b) { ... }
}

Then the compiler (correctly) rejects the whole thing with the following 
message:

Test.java:15: types B and A are incompatible; both define get(), but 
with unrelated default implementations
      private static class X implements A, B { }
                     ^
1 error

If Implementations only define a method like:

class Implementations {
    static int one(Object o) { ... }
}

The compiler seems to be able to accept this w/o problems. But this 
could be a consequence of the latest changes I have in my repo - I will 
push changes soon.

Maurizio


More information about the lambda-dev mailing list