Stream reuse in superclass
David Holmes
david.holmes at oracle.com
Thu Apr 4 18:31:18 PDT 2013
On 5/04/2013 6:59 AM, Jose wrote:
> I have a class that contains a method that consumes a Stream (previously was
> a Collection)
And that is your problem. You can not think of operations on a stream
the way you would a collection, as a stream is not a collection. Your
class that operated on the elements of the collection would now become
an operation to be passed to a suitable stream method to be applied to
each element.
David
> Class Foo<T>{
> bar(Stream<T> s){
> .........
> }
> }
>
>
> This method is overriden in a subclass, that first consumes the stream and
> then calls super
>
> Class PowerFoo<T> extends Foo<T>{
> bar(Stream<T> s){
> doImportantThingsWidth(s);
> //now the stream is consumed :-(
> super.bar(s)
> }
> }
>
>
> What is the recomended way to handle situations like this?.
>
> Curently I'm collecting the stream into a list and getting two streams from
> it.
>
>
More information about the lambda-dev
mailing list