[英]Java8 .getMethod() vs ::getMethod
I am new in Java8 ,and I created this piece of code that is working fine 我是Java8的新手,我创建了一段工作正常的代码
userService.getClient().findUsersByMarkets(marketIds)
.stream()
.filter(us -> !alreadyNotifiedUserIds.contains(us.getId()))
.forEach(usersToBeNotified::add);
but under my understandings this piece of code should also work fine, but is not the case and I am wondering why 但根据我的理解,这段代码也应该工作正常,但事实并非如此,我想知道为什么
userService.getClient().findUsersByMarkets(marketIds)
.stream()
.filter(us -> !alreadyNotifiedUserIds.contains(User::getId))
.forEach(usersToBeNotified::add);
User::getId
is a reference to a function so it's not equivalent to contains(us.getId())
. User::getId
是对函数的引用,因此它不等于contains(us.getId())
。
see --> https://www.codementor.io/eh3rrera/using-java-8-method-reference-du10866vx to familiarise your self with method references. 请参阅 - > https://www.codementor.io/eh3rrera/using-java-8-method-reference-du10866vx以熟悉您的方法参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.