我是Java8的新手,我创建了这段运行良好的代码。
userService.getClient().findUsersByMarkets(marketIds)
.stream()
.filter(us -> !alreadyNotifiedUserIds.contains(us.getId()))
.forEach(usersToBeNotified::add);但根据我的理解,这段代码也应该能正常工作,但事实并非如此,我想知道为什么。
userService.getClient().findUsersByMarkets(marketIds)
.stream()
.filter(us -> !alreadyNotifiedUserIds.contains(User::getId))
.forEach(usersToBeNotified::add);发布于 2018-11-30 15:30:56
User::getId是对函数的引用,因此它不等同于contains(us.getId())。
参见-> https://www.codementor.io/eh3rrera/using-java-8-method-reference-du10866vx,以使您熟悉方法引用。
https://stackoverflow.com/questions/53560419
复制相似问题