-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8
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-
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-
- duplicates
-
JDK-8170560 Improve code samples in Collectors javadoc
-
- Closed
-