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

2012-01-23 Thread 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 th

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

2012-01-23 Thread Noctarius
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

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

2012-01-23 Thread Charles Oliver Nutter
Oh, that does seem to work...what an ugly hack. And actually, you can just use Object.class but cast the resulting return to void, and it works. So basically, I do this: handler = MethodHandles.constant(Object.class, null) handler = MethodHandles.asType(void.class) handler = MethodHandles.dropArg