Why the tryAdvance of stream.spliterator() may accumulate items into a buffer?

后端 未结 4 906
野趣味
野趣味 2021-01-02 17:32

Getting a Spliterator from a Stream pipeline may return an instance of a StreamSpliterators.WrappingSpliterator. For example, getting the following

4条回答
  •  醉酒成梦
    2021-01-02 18:28

    Spliterators are designed to handle sequential processing of each item in encounter order, and parallel processing of items in some order. Each method of the Spliterator must be able to support both early binding and late binding. The buffering is intended to gather data into suitable, processable chunks, that follow the requirements for ordering, parallelization and mutability.

    In other words, tryAdvance() is not the only method in the class, and other methods have to work with each other to deliver the external contract. To do that, in the face of sub-classes that may override some or all of the methods, requires that each method obey its internal contract.

提交回复
热议问题