amarnath harish
amarnath harish

Reputation: 971

Does stream use CHARACTERISTICS of the stream source?

from this question

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

  1. under what circumstances stream API considers characteristics ?
  2. which operation resets which characteristics ?

Upvotes: 4

Views: 154

Answers (1)

Eugene
Eugene

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

Related Questions