Default methods

Attila Szegedi attila.szegedi at oracle.com
Thu Sep 24 13:36:34 UTC 2015


Axel,

thanks for a very comprehensive demonstration of the problem. I agree these should work; I’ll investigate to see what’s up with them. I raised https://bugs.openjdk.java.net/browse/JDK-8137093 <https://bugs.openjdk.java.net/browse/JDK-8137093> to track the issue.

Thanks,
  Attila.

> On Sep 24, 2015, at 1:02 PM, Axel Dörfler <axeld at pinc-software.de> wrote:
> 
> Hi there,
> 
> I'm currently trying to implement an interface from JavaScript that has default implementations. Unfortunately, it's not working.
> 
> That's the code at the Java side:
>    interface A {
>        default void a() {
>            System.out.println("a");
>        }
>    }
>    interface B extends A {
>        default void b() {
>            System.out.println("b");
>        }
>        default void c() {
>            System.out.println("c");
>        }
>    }
> 
> And that's the one in JavaScript:
>    var B = Java.type("my.package.B");
>    new B({
> 	b: function() {
> 		doMyStuff();
> 	}
>    });
> 
> If I invoke a() on the new object, I get the following error:
>    java.lang.IncompatibleClassChangeError: Interface method reference: my.package.A.a(;)Z, is in an indirect superinterface of my.package.B$$NashornJavaAdapter
> 
> The same works just fine in Java, so I assume that this is an actual bug in the Nashorn implementation, as I can invoke c() without a problem.
> Is this known or even accepted behavior?
> 
> Also, when I create a class of this:
> public class C implements B {
> }
> 
> I cannot use the following:
>    var C = Java.type("my.package.C");
>    new C({
>        b: function() {
> 	    doMyStuff();
> 	}
>    });
> 
> I get this error:
> javax.script.ScriptException: TypeError: Can not construct my.package.C with the passed arguments; they do not match any of its constructor signatures. in <eval> at line number 2
> 
> Removing the default methods, all is working as expected.
> 
> Kind regards,
>   Axel Dörfler.



More information about the nashorn-dev mailing list