I face the same problem often. I need to count the runs of a lambda for use outside the lambda.
E.g.:
myStream.stream().filter(...).forEa
If you don't want to create a field because you only need it locally, you can store it in an anonymous class:
int runCount = new Object() {
int runCount = 0;
{
myStream.stream()
.filter(...)
.peek(x -> runCount++)
.forEach(...);
}
}.runCount;
Weird, I know. But it does keep the temporary variable out of even local scope.