creating proxies for interfaces with default methods

Mandy Chung mandy.chung at oracle.com
Wed May 25 20:32:36 UTC 2016


> On May 25, 2016, at 1:12 PM, Jochen Theodorou <blackdrag at gmx.org> wrote:
> 
>>> Dynamic proxies and invocation handlers won't do the job, as they do not
>>> provide an implementation of the interface I can call the default method
>>> on.
>> 
>> Is this a general limitation of j.l.r.Proxy? At first glance it doesn't
>> seem like you're hitting an accessibility issue due to Jigsaw.

I agree this is not related to jigsaw.

The generated proxy class does not treat default methods any different than interface methods.  The invocation handler will be the one handling it in its intended way.  As you said, you need a way to invoke the default method with reflection for implementing such an invocation handler.

> 
> I have not found a way to call a default method with reflection. I have no instance of the interface in the Proxy, so what am I supposed to call the method on? Java can use an invokespecial on the interface method, but you cannot do an invokespecial with reflection (to me knowledge). With MethodHandles you can in theory do that - it exceeds my knowledge on what you actually call it, since there is no implementation. But then again, what if the default method calls another method of the interface? what is "this" there?

Perhaps you can ask this at mlvm-dev at openjdk.java.net

Mandy


More information about the jigsaw-dev mailing list