Reputation: 2056
I have this piece of code :
userAvailableRoles.stream()
.peek(x-> x.setPets(userPets(roles, hasValidAccess)));
but I have this warning:
Warning:(86, 18) Result of 'Stream.peek()' is ignored
Upvotes: 0
Views: 1662
Reputation: 311163
peek
returns a stream of elements after the consumer is applied to them. Here, you ignore this returned stream, which produces the warning.
If you just need to call setPets
on all the elements of userAvailableRoles
you should probably use forEach
and not peek
:
userAvailableRoles.forEach(x-> x.setPets(userPets(roles, hasValidAccess)));
Upvotes: 8
Reputation: 2428
peek
returns a stream with the same elements for further processing. If you don't need that you should use forEach
instead.
Upvotes: 4