lambdasinaction code example Eorror In Chap3
Closed this issue · 2 comments
I downloaded the lambdasinaction code example, but there are some errors.
For example:
The method flatMapping(( dish) -> {}, toSet()) is undefined for the type Grouping in chap3 package, The code: private static Map<Dish.Type, Set<String>> groupDishTagsByType() { return menu.stream().collect(groupingBy(Dish::getType, flatMapping(dish -> dishTags.get( dish.getName() ).stream(), toSet()))); }
And The method filtering(( dish) -> {}, toList()) is undefined for the type Grouping in chap3 package, The code private static Map<Dish.Type, List<Dish>> groupCaloricDishesByType() { return menu.stream().collect(groupingBy(Dish::getType, filtering(dish -> dish.getCalories() > 500, toList()))); }
When I practice, encountered a lot of errors . The method toList() 、groupingBy、comparing()....is undefined for the type TestStream.
By the way, i used jdk 1.8.0.171,Is it because the JDK version is too low ?
This is because the source code was updated to Java 9.
takeWhile is a new method added to Stream interface in Java 9:
filtering and flatMapping where added to the Collectors interface:
So, update to JDK 9.
thank you,I see in pom.xml that the environment needs jdk9. but this book is jdk8Inaction.
Well, i admit i was careless...
by the way, i download jdk9. its no many jar,eg:rt.jar,resource.jar...
so, i cannot use jdk9