RFR: 8159746: (proxy) Support for default methods

Mandy Chung mchung at openjdk.java.net
Thu Oct 15 02:57:16 UTC 2020


On Wed, 7 Oct 2020 21:31:29 GMT, Mandy Chung <mchung at openjdk.org> wrote:

>> I'm thinking a static method `InvocationHandler::invokeDefaultMethod` and no new method in `Proxy` class.   Proxy class
>> will still have the package-private methods for `InvocationHandler::invokeDefaultMethod` implementation to use.
>> It may seem to be cleaner to be a default method at the use site called from InvocationHandler.  However, it's not
>> really a method meant to be overridden.
>
> Thanks for the input Peter.
> 
>> I'm in favour of following the bytecode (method handles) behaviour here even though it allows more than Java language
>> allows.
> 
> The proposal intends to follow the bytecode behavior.   I can clarify in the javadoc.

`invokeDefaultMethod` is moved to a static method in `InvocationHandler`.
 I also add `@throws IllegalAccessException` if the specified default method is
inaccessible to the caller (access check was missing in the previous version).
The declaring interface of the default method must be exported to the caller to
use.  If it's a non-public interface, the caller class must be in the same runtime
package as the interface.  The example in javadoc includes the case when
the proxy interface is modified.

-------------

PR: https://git.openjdk.java.net/jdk/pull/313


More information about the core-libs-dev mailing list