Early/late binding to data source (original) (raw)

Remi Forax forax at univ-mlv.fr
Thu Nov 29 10:12:45 PST 2012


On 11/29/2012 05:29 PM, Brian Goetz wrote:

We've already committed to a model where stream operations do not tolerate modification of their data source during the operation. For example, this is illegal:

collection.stream().forEach(e -> collection.removeAll(e));

by illegal, it hopes it means it should throw a ConcurrentModificationException and not the result is random, good luck.

We've also tightened down the spec on "source sharing" and "stream reuse". We now have to define what "during" means. We make a substantial effort to not touch the data until the user wants to do something with it. So, what should happen in this case: List strings = new ArrayList<>(Arrays.asList("a")); Stream s = strings.stream(); strings.clear(); s.forEach(System.out::println);

It should print nothing, creating a stream, filter it etc. are lazy operations, only terminal ops do something.

Rémi



More information about the lambda-libs-spec-observers mailing list