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

Add a dropReturn MethodHandle combinator

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 16
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Since this is a new API, whose implementation doesn't change any existing code, there is virtually no compatibility risk.
    • Interface Kind:
      Java API
    • Scope:
      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

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

                Dates

                Created:
                Updated:
                Resolved: