I am new in Java8 ,and I created this piece of code that is working fine
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())
.
see --> https://www.codementor.io/eh3rrera/using-java-8-method-reference-du10866vx to familiarise your self with method references.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.