invoking a interface default method from within an InvocationHandler

Alessio Stalla alessiostalla at gmail.com
Thu Oct 9 15:32:49 UTC 2014


On Thu, Oct 9, 2014 at 5:22 PM, Jochen Theodorou <blackdrag at gmx.org> wrote:

> Am 09.10.2014 17:02, schrieb Alessio Stalla:
>
>> "All problems in computer science can be solved by another level of
>> indirection"... "except for the problem of too many layers of
>> indirection".
>>
>> What about (untested):
>>
>> Consumer proxy = Proxy.newProxyInstance(...);
>> Consumer myConsumer = proxy::accept;
>>
>> If you keep the proxy inaccessible, nobody will ever call andThen on it.
>>
>
> I wonder if I find this genius or just ill, lol.
> Have not tested it yet, but I guess it would solve the problem for
> functional interfaces.... what about an interface with 3 methods, of which
> only one is a default one? A InvocationHandler can handle more than one
> method, lambda conversion cannot.


Well, you can extend this technique by using more method references and
delegation (yes, even more levels of indirection!), but frankly if you
could have doubts about the solution with a functional interface, this one
would triumphantly jump over the line between "nice hack" and "horrible,
horrible code".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20141009/bf7ff535/attachment-0001.html>


More information about the mlvm-dev mailing list