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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8
    • core-libs

      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-

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: