【发布时间】:2021-04-15 05:20:58
【问题描述】:
我有一个使用属性分组的列表。我不知道为什么会出错
类型不匹配:无法从 Map
调用领导者类时。我正在使用 Java 8。
Map<String, List<Leader>> reports = vals.stream()
.collect(
Collectors.mapping(val -> val.split("\\|"),
Collectors.mapping(leaderArgs -> new Reports(leaderArgs[0], leaderArgs[1], leaderArgs[2], leaderArgs[3]),
Collectors.groupingBy(leader -> leader.country))));
```java
public class Leader {
String name;
String country;
String age;
String sex;
Leader(String name, String country, String age, String sex) {
this.name = name;
this.country = country;
this.age = age;
this.sex = sex;
}
}
【问题讨论】:
-
这无法编译 - 您正在为您的班级使用 4 个名称 -
Leaders、Reports、Leader、Report。将所有这些更改为Leader就可以了。 -
@greg-449 仍然出现同样的错误。
-
您使用的是什么版本的 Eclipse?更正后的代码在当前的 Eclipse 2021-03 上很好
-
@greg-449 我正在使用 Eclipse Photon v4.8.0
-
那么 Eclipse Photon 现在已经过时了 11 个版本,很可能已经修复了较新版本中流的类型推断代码,因为这是一个非常棘手的领域。
标签: java eclipse maven mismatch