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

Collectors.reducing(U, Function, BinaryOperator) documenation example doesn't match method

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      A DESCRIPTION OF THE PROBLEM :
      The provided example does not provide an identity value to the reducing Collector factory method

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      For example, given a stream of Person, to calculate the longest last name of residents in each city:


           Comparator<String> byLength = Comparator.comparing(String::length);
           Map<City, String> longestLastNameByCity
               = people.stream().collect(groupingBy(Person::getCity,
                                                    reducing("", Person::getLastName, BinaryOperator.maxBy(byLength))));
      ACTUAL -
      For example, given a stream of Person, to calculate the longest last name of residents in each city:


           Comparator<String> byLength = Comparator.comparing(String::length);
           Map<City, String> longestLastNameByCity
               = people.stream().collect(groupingBy(Person::getCity,
                                                    reducing(Person::getLastName, BinaryOperator.maxBy(byLength))));

      URL OF FAULTY DOCUMENTATION :
      https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html#reducing-U-java.util.function.Function-java.util.function.BinaryOperator-

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psonal Pallavi Sonal
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: