Nuñito Calzada
Nuñito Calzada

Reputation: 2056

Warning:(86, 18) Result of 'Stream.peek()' is ignored

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

Answers (2)

Mureinik
Mureinik

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

Imre Kerr
Imre Kerr

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

Related Questions