Reputation: 971
a spliterator reporting either, IMMUTABLE or CONCURRENT, is guaranteed to never throw a ConcurrentModificationException. Of course, CONCURRENT precludes SIZED semantically, but that has no consequence to the client code.
In fact, these characteristics are not used for anything in the Stream API, hence, using them inconsistently would never get noticed somewhere.
This is also the explanation why every intermediate operation has the effect of clearing the CONCURRENT, IMMUTABLE and NONNULL characteristics: the Stream implementation doesn’t use them and its internal classes representing the stream state do not maintain them.
if stream doesnt use CHARACTERISTICS from source then how stream works parallely? does stream completely ignores the stream source characteristics?
from this question Collector does not know that im using a concurrent collection provided by Supplier, so characteristics are not infered from type of collector container
Upvotes: 4
Views: 154
Reputation: 120868
What you are asking for is possible. The correct verbiage in those answers, would be that at the moment those properties are ignored, in some future they might be injected/read/used by stream implementation.
Also in your comments, you say that:
someTreeSet().stream()
.sorted()
.... some other operations
Will call sorted
. This is simply not true, in this case, that operation will not get called. This is one stream flag that is not ignored and injected into the stream implemntation by TreeSet
.
Upvotes: 6