Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9545

DGM: add toArray(Class) extension method for java.util.stream.Stream

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 4.x, 3.0.3
    • Fix Version/s: 4.0.0-alpha-1, 3.0.4
    • Component/s: groovy-jdk
    • Labels:
      None

      Description

      Proposal to add a new extension method for Stream that returns a typed array with minimal boilerplate (i.e. is somewhere in between toArray() and toArray(IntFunction):

      void test(List<String> list) {
        def array = list.stream().toArray() // returns Object[]
        array = list.stream().toArray(String) // returns String[] -- proposed extension
        array = list.stream().toArray(String[]::new) // returns String[] but requires "[]::new"
      }
      

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              emilles Eric Milles
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 40m
                40m