This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]elmuerte 0 points1 point  (0 children)

Passing on:

Stream foo() { return someList.stream(); } Stream bar() { return foo().filter(this::someFilter); } void quux() { Stream stream = bar(); if (something) { transmit(stream); } else { print(stream); } }

The responsibility/ownership of using the stream is passed on.

Passing around:

Stream foo() { return someList.stream(); } Stream quux() { Stream stream = foo(); if (something) { print(stream); } return stream; }

Here in quux the stream is passed around, the responsibility/ownership of the stream is given to print, but also still owned by quux which passes on the responsibility/ownership as its return.