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

API Note example is wrong

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      The example in the API Note is wrong, it doesn compile. The identity value is missing in the reduce method call.

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

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
        Map<City, String> longestLastNameByCity
               = people.stream().collect(groupingBy(Person::getCity,
                                                    reducing("",Person::getLastName, BinaryOperator.maxBy(byLength))));
      ACTUAL -
        Map<City, String> longestLastNameByCity
               = people.stream().collect(groupingBy(Person::getCity,
                                                    reducing(Person::getLastName, BinaryOperator.maxBy(byLength))));

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

            aroy Abhijit Roy (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: