Stream
API calls like map()
, or boxed()
right before the count()
call.
Such calls don't change the final count, so could be removed. It's possible that the code relies on a side effect from the lambda inside such a mapping call. However, relying on side effects inside the stream chain is extremely bad practice. There are no guarantees that the call will not be optimized out in future Java versions.
Example:
// map() call is redundant
long count = list.stream().filter(s -> !s.isEmpty()).map(s -> s.trim()).count();
New in 2024.1