【发布时间】:2018-10-21 20:36:14
【问题描述】:
我有一个元素列表,我想在 forEach 元素中创建一个构造函数,但出现错误:Cannot invoke forEach(( de) -> {}) on the original type void
List<MatchEventMobileApp> matchEventMobileApp
= new ArrayList<matchEventMobileApp>();
matchEventService
.findAllByMatch(“JVT”))
.sort(Comparator.comparing(MatchEvent::getDateReceived))
.forEach(de -> matchEventMobileApp.add(new MatchEventMobileApp(de)));
public List<MatchEvent> findAllByMatch(Match match) {
return matchEventRepository.findAllByMatch(match);
}
【问题讨论】:
-
我的猜测是
findAllByMatch返回一个List,而List#sort(Comparator)返回void,因为它就地修改了列表。 -
请添加
findAllByMatch方法签名,@Clashsoft 很可能是正确的
标签: java collections java-8