Java 8 Stream IllegalStateException: Stream has already been operated on or closed

前端 未结 6 674
孤独总比滥情好
孤独总比滥情好 2020-11-27 07:45

I\'m trying to generate Order instances using the Stream API. I have a factory function that creates the order, and a DoubleStream is used to initialize the amount of the o

6条回答
  •  难免孤独
    2020-11-27 08:43

    You should use Supplier function interface for your initialization like this

    Supplier> streamSupplier = () -> (new Random().doubles(50.0, 200.0).boxed());
    

    And change your way to get double like this

    streamSupplier.get().findFirst().get()
    

    Then it works normally.

    Found this way from the post Stream has already been operated upon or closed Exception

提交回复
热议问题