RFR: 8255398: Add a dropReturn MethodHandle combinator [v3]

John R Rose jrose at openjdk.java.net
Mon Oct 26 17:19:19 UTC 2020


On Mon, 26 Oct 2020 15:45:00 GMT, Claes Redestad <redestad at openjdk.org> wrote:

>> Jorn Vernee has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Collapse lform get and update into single line
>>   
>>   Co-authored-by: Claes Redestad <claes.redestad at gmail.com>
>
> LGTM, pending CSR.
> 
> A minor simplification suggested inline.

I don't mind shorthands, but the existing idiom is shorter than advertised,
a one-liner assuming the MH is already bound to a var:

target = target.asType(target.type().changeReturnType(void.class));

The API has good short circuits already; no new objects are
created if the MH is already void-returning.

Perhaps this RFE could be adjusted to `MethodHandle::changeReturnType`?
Then it could be used for dropping returns *or* casting them to other types.

-------------

PR: https://git.openjdk.java.net/jdk/pull/866


More information about the core-libs-dev mailing list