java8 / Java8InAction

MIT License
3.19k stars 2.26k forks source link

Grouping class has two errors with undefined functions at line 36 and 41 #15

Open wilsonpenha opened 7 years ago

wilsonpenha commented 7 years ago

private static Map<Dish.Type, Set> groupDishTagsByType() { return menu.stream().collect(groupingBy(Dish::getType, flatMapping(dish -> dishTags.get( dish.getName() ).stream(), toSet()))); } -> flatMapping shown as invalid and don't compile the class

private static Map<Dish.Type, List<Dish>> groupCaloricDishesByType() {

// return menu.stream().filter(dish -> dish.getCalories() > 500).collect(groupingBy(Dish::getType)); return menu.stream().collect(groupingBy(Dish::getType, filtering(dish -> dish.getCalories() > 500, toList()))); } -> filtering shown as invalid and don't compile the class

bsbravo commented 6 years ago

This is because the source code was updated to Java 9.

takeWhile is a new method added to Stream interface in Java 9:

https://docs.oracle.com/javase/9/docs/api/java/util/stream/Stream.html#takeWhile-java.util.function.Predicate-

filtering and flatMapping where added to the Collectors interface:

https://docs.oracle.com/javase/9/docs/api/java/util/stream/Collectors.html#flatMapping-java.util.function.Function-java.util.stream.Collector-

https://docs.oracle.com/javase/9/docs/api/java/util/stream/Collectors.html#filtering-java.util.function.Predicate-java.util.stream.Collector-

labazhou2018 commented 6 years ago

This book's name is Java8InAcation. However the source has already updated to Java9.