Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8255398

Add a dropReturn MethodHandle combinator

    XMLWordPrintable

Details

    • CSR
    • Status: Closed
    • P4
    • Resolution: Approved
    • 16
    • core-libs
    • None
    • behavioral
    • minimal
    • Since this is a new API, whose implementation doesn't change any existing code, there is virtually no compatibility risk.
    • Java API
    • SE

    Description

      Summary

      Add a dropReturn method handle combinator, that can be used to drop the return value of a method handle.

      Problem

      There are currently several methods in j.l.i.MethodHandles for dropping arguments, but a similar combinator does not exist for dropping return values. Instead other means such as using a combination of filterReturn and empty, or asType with a void return type have to be used to create a method handle that discards the return value.

      Solution

      Provide a dropReturn method handle combinator that takes a MethodHandle, and returns a new MethodHandle that is the same as the given method handle, but which discards it's return value.

      Specification

      /**
       * Drop the return value of the target handle (if any).
       * The returned method handle will have a {@code void} return type.
       *
       * @param target the method handle to adapt
       * @return a possibly adapted method handle
       * @throws NullPointerException if {@code target} is null
       * @since 16
       */
      public static MethodHandle dropReturn(MethodHandle target) {
          ...
      }

      Attachments

        Issue Links

          Activity

            People

              jvernee Jorn Vernee
              jvernee Jorn Vernee
              Claes Redestad
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: