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

Claes Redestad redestad at openjdk.java.net
Mon Oct 26 15:48:47 UTC 2020


On Mon, 26 Oct 2020 15:45:34 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> Hi,
>> 
>> This patch adds a `dropReturn` combinator to `MethodHandles` that can be used to create a new method handle that drops the return value, from a given method handle. Similar to the following code:
>> 
>> MethodHandle target = ...;
>> Class<?> targetReturnType = target.type().returnType();
>> if (targetReturnType != void.class)
>>     target = filterReturnValue(target, empty(methodType(void.class, targetReturnType))); 
>> // use target
>> 
>> But as a short-hand.
>> 
>> Thanks,
>> Jorn
>
> Jorn Vernee has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix bug id referenced in test

LGTM, pending CSR.

A minor simplification suggested inline.

src/java.base/share/classes/java/lang/invoke/MethodHandles.java line 5225:

> 5223:         MethodType newType = oldType.changeReturnType(void.class);
> 5224:         BoundMethodHandle result = target.rebind();
> 5225:         LambdaForm lform = result.form;

Suggestion:

        LambdaForm lform = result.editor().filterReturnForm(V_TYPE, true);

src/java.base/share/classes/java/lang/invoke/MethodHandles.java line 5226:

> 5224:         BoundMethodHandle result = target.rebind();
> 5225:         LambdaForm lform = result.form;
> 5226:         lform = lform.editor().filterReturnForm(V_TYPE, true);

Suggestion:

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

Marked as reviewed by redestad (Reviewer).

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


More information about the core-libs-dev mailing list