Someone raised a question on another SO Answer about whether it is bad practice or inefficient to do this:
Optional<User> user = ...
user.ifPresent(u -> doSomethingWithoutUser());
instead of
if (user.isPresent()) doSomethingWithoutUser();
Specifically, the fact that we're adapting a zero-arg method into a Consumer<User>
which ignores its parameter u
.
- As this isn't a Stream non-terminal operation, the fact
doSomethingWithoutUser()
likely has side-effects isn't a concern. - I'm not bothered about the specifics of this one-line Optional example, it could the result of a long chain of functional/Stream calls that simply feels natural to finish inline with the lambda call.