----- Mail original ----- > De: "Peter Levart" <peter.lev...@gmail.com> > À: fo...@univ-mlv.fr > Cc: "Da Vinci Machine Project" <mlvm-dev@openjdk.java.net>, "jochen > Theodorou" <blackd...@gmx.org> > Envoyé: Jeudi 2 Juin 2016 15:23:44 > Objet: Re: proxy an interface and call a default method
> Hi Remi, Jochen, > On 06/02/2016 11:15 AM, fo...@univ-mlv.fr wrote: > > > > The solution could be for Proxy API to provide a MH that was already > > > > > bound to the Proxy instance. Such pre-bound MH could not be abused > > > > then. > > > > > independently of any security issue, it may be a good idea but doing a > > partial evaluation on a MH is not cheap. > > I created a prototype for this: > http://cr.openjdk.java.net/~plevart/jdk9-dev/Proxy.invokeSuperDefaults/webrev.01/ > Example usage is as follows: > public class Test { > interface I { > default void m() { > System.out.println("default I.m() called"); > } > } > public static void main(String[] args) { > InvocationHandler h = (proxy, method, params) -> { > System.out.println("InvocationHandler called for: " + method); > MethodHandle superM = ((Proxy) proxy).findSuper(I.class, "m", > MethodType.methodType(void.class)); > return superM.invokeWithArguments(params); > }; > I i = (I) Proxy.newProxyInstance( > I.class.getClassLoader(), new Class<?>[]{I.class}, h); > i.m(); > } > } > It works, but in order for this to have adequate performance, caching would > have to be added. But caching a pre-bound MH would require caching on > per-proxy-instance basis, which would not be very efficient. So perhaps, > instead of providing a Proxy::findSuper method that returns a pre-bound MH, > there could simply be a method like the following in the Proxy class: > public final Object invokeSuper(Class<?> interfaze, String methodName, > MethodType methodType, Object ... args) { ... } > What do you think? yes, good idea, i think it should be static (and takes a Proxy as parameter) to avoid unwanted overriding. > Regards, Peter Rémi
_______________________________________________ mlvm-dev mailing list mlvm-dev@openjdk.java.net http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev