Stream reuse in superclass

Brian Goetz brian.goetz at
Fri Apr 5 06:56:59 PDT 2013

>   public void addRows(Stream<Foo> rows) {
>          rows=rows.peek(row -> row.addReceiver(this));

Actually this won't do anything -- peek is not a terminal operation.

But in your case, I think the issue is the tension between wanting to 
add the rows in bulk before firing the change event, and wanting to get 
access to each one as it is added.  THat's not a stream problem :) 
There's a simple refactor here:

   public void bulkAdd(Stream<R> rows) {
       rows.forEach(r -> singleAdd(r));

   protected void singleAdd(R row) {

Now the subclass overrides singleAdd.

More information about the lambda-dev mailing list