Is the requirement of non-interference required to use streams of non-competitive sources of the data structure that we cannot change the state of the data structure element during the execution of the stream pipeline (in addition to this, we can’t "change the original data structure)? (Question 1)
The non-interference section in the description of the stream package states: "For most data sources, interference prevention means that the data source will not be altered at all during the execution of the stream pipeline."
Does this passage not mention the state change of elements?
For example, assuming “shapes” are not a thread-safe collection (such as an ArrayList ), is the code below a hindrance? (Question 2)
shapes.stream() .filter(s -> s.getColor() == BLUE) .forEach(s -> s.setColor(RED));
This example is taken from a reliable source (at least), so it should be correct. But what if I changed stream() to parallelStream() , would it still be safe and correct? (Question 3)
On the other hand, the “Development of Lambdas” by Naftalin Moris, another reliable source, makes it clear that a change in the state (value) of elements in a pipeline operation is indeed an obstacle. From the section on non-intervention (3.2.3):
"But the rules for threads forbid any modification of the sources of a stream, including, for example, changing the value of an element - for any stream, and not just operations with the pipeline."
If what is said in the book is correct, does this mean that we cannot use the stream API to change the state of elements (using forEach ) and should do it using a regular iterator (or for each, or Iterable.forEach )? (Question 4)