creating proxies for interfaces with default methods

Jochen Theodorou blackdrag at gmx.org
Wed May 25 07:22:07 UTC 2016


Hi all,

so in earlier mails to this list I described a bit the problems I got 
into with the way Groovy produces proxies and handles default methods 
for those.

I would like to see how the correct solution to this is supposed to be....

so we have code like m.sortReversed{a,b -> a.value <=> b.value}, where 
sortReversed is getting a Comperator and will call reversed() on it. 
This is not actual API, this is just an example! So far the logic has 
been, that kind of lambda {a,b -> a.value <=> b.value}, is called for 
every non-default, non-static method. If we are talking about functional 
interfaces, there is only one such method. The problem now arises what 
we are supposed to do if a default method is called.

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.

Which means I have to use LambdaMetaFactory or maybe 
MethodHandleProxies. This may solve the problem...

A second usage is for a kind of mocking. which means we have either a 
map of lambdas, or a lambda which can accept any kind of argument 
constellation...and now multiple non-static, non-default methods to 
proxy. We did use dynamic proxies for that in the past. I do not see how 
that can work with either of the three.

So runtime generated classes is the only option left? Including all the 
problems with class loaders....

bye Jochen




More information about the jigsaw-dev mailing list