• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

stream has already been operated upon or closed

 
Ranch Hand
Posts: 211
27
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why this code throws "java.lang.IllegalStateException: stream has already been operated upon or closed" exception? There is no terminal operation here.
Everthing will be ok if I uncomment "line a".
 
Saloon Keeper
Posts: 10407
223
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A stream is closed when a terminal operation is called. A stream is operated on when you call *any* stream operation.

You bind two operations to the stream you create on line 3: the mapToInt() on line 4 and the mapToDouble() on line 6. That's not allowed.
 
Mushfiq Mammadov
Ranch Hand
Posts: 211
27
IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:A stream is operated on when you call *any* stream operation.


This was helpful. Thank you for your response.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!