問題文
A pipeline is built from a list with a filter step and a map step, and the resulting stream is assigned to a variable. Nothing else is done with it. What happens?
選択肢
- The filter step runs immediately so that the number of remaining elements is known, and only the map step is deferred until a terminal operation arrives.
- An IllegalStateException is thrown as soon as the pipeline is assigned to a variable without a terminal operation, and a stream must be consumed exactly once before it goes out of scope.
- Neither step runs, because intermediate operations are lazy and do nothing until a terminal operation is invoked on that stream.
- Both steps run immediately, and the stream then holds the transformed values, which a later call can read.