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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With