首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java8 .getMethod() vs ::getMethod

Java8 .getMethod() vs ::getMethod
EN

Stack Overflow用户
提问于 2018-11-30 15:29:16
回答 1查看 181关注 0票数 5

我是Java8的新手,我创建了这段运行良好的代码。

代码语言:javascript
复制
 userService.getClient().findUsersByMarkets(marketIds)
                .stream()
                .filter(us -> !alreadyNotifiedUserIds.contains(us.getId()))
                .forEach(usersToBeNotified::add);

但根据我的理解,这段代码也应该能正常工作,但事实并非如此,我想知道为什么。

代码语言:javascript
复制
     userService.getClient().findUsersByMarkets(marketIds)
        .stream()
        .filter(us -> !alreadyNotifiedUserIds.contains(User::getId))
        .forEach(usersToBeNotified::add);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-30 15:30:56

User::getId是对函数的引用,因此它不等同于contains(us.getId())

参见-> https://www.codementor.io/eh3rrera/using-java-8-method-reference-du10866vx,以使您熟悉方法引用。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53560419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档