【发布时间】:2019-02-03 17:14:55
【问题描述】:
我正在使用 Java 8,但第 30 行的代码出现以下错误
方法 flatMapping(( disc) -> {}, toSet()) 没有为 Grouping 类型定义
public class Grouping {
enum CaloricLevel { DIET, NORMAL, FAT };
public static void main(String[] args) {
System.out.println("Dishes grouped by type: " + groupDishesByType());
System.out.println("Dish names grouped by type: " + groupDishNamesByType());
System.out.println("Dish tags grouped by type: " + groupDishTagsByType());
}
private static Map<Type, List<Dish>> groupDishesByType() {
return Dish.menu.stream().collect(groupingBy(Dish::getType));
}
private static Map<Type, List<String>> groupDishNamesByType() {
return Dish.menu.stream().collect(groupingBy(Dish::getType, mapping(Dish::getName, toList())));
}
private static String groupDishTagsByType() {
/*line:30*/ return menu.stream().collect(groupingBy(Dish::getType, flatMapping(dish -> dishTags.get( dish.getName() ).stream(), toSet())));
}
}
【问题讨论】:
-
注意:建议您分享问题中的代码而不是图像,以便于重现。
标签: java java-8 java-stream collectors