No way to create a no-op MethodHandle that returns void?

Noctarius me at noctarius.com
Mon Jan 23 23:07:59 PST 2012


Hi Charly,

why not use Void and return null what behaves like using void as
the return type.

Cheers
Chris

Am 24.01.2012 08:01, schrieb Charles Oliver Nutter:
> I discovered a possible gap in the MethodHandles API.
> 
> Say I want to create an exception handler that does nothing but
> ignore the exception. The target handle is a method that looks
> like this:
> 
> void foo(String)
> 
> I have my "target" handle pointing at foo.
> 
> I want to catch all Throwable and ignore them, so I would build
> up a method handle chain that does the following (top-down)
> 
> 1. receives arguments (Throwable, String) and returns void 2.
> drops both arguments 3. ???
> 
> There's no endpoint I can attach it to for a "no-op" void
> return.
> 
> "constant" doesn't work because it returns a value, and
> explicitly forbids void return type.
> 
> "identity" doesn't work because it returns a value and receives
> one argument.
> 
> What I need here is something like MethodHandles.constant, but
> that takes no arguments and has a void return.
> MethodHandles.nop anyone?
> 
> I could filterReturn, but I still would have to attach it to
> an external method...there's no way to create a filter that
> returns void entirely with method handles.
> 
> Am I missing something?
> 
> - Charlie _______________________________________________ 
> mlvm-dev mailing list mlvm-dev at openjdk.java.net 
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev


-- 


##############################
# A Digital's Life           #
##############################
Nickname: Noctarius
Location: Germany

Meet me at:
Ohloh: http://www.ohloh.net/accounts/noctarius
Web: http://www.noctarius.com
XMPP/Jabber: noctarius at jabber.ccc.de


More information about the mlvm-dev mailing list