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

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

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.x, 3.0.3
    • 4.0.0-alpha-1, 3.0.4
    • groovy-jdk
    • 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

            emilles Eric Milles
            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