티스토리 뷰

개발

stream has already been operated upon or closed

달리는개발자 2022. 6. 20. 15:06

아래와 같이 Stream을 재사용하는 경우에 발생함.

@Test
void test() {
	IntStream intStream = IntStream.rangeClosed(1, 100);

	intStream.forEach(System.out::println);
	intStream.forEach(System.out::println);
}
A Stream should be operated on (invoking an intermediate or terminal stream operation) only once. A Stream implementation may throw IllegalStateException if it detects that the Stream is being reused.

 

재사용이 필요한 곳에서는 Stream을 재생성한 후에 사용한다.

 

참고

https://www.baeldung.com/java-stream-operated-upon-or-closed-exception

 

"Stream has already been operated upon or closed" Exception in Java | Baeldung

Discover how to solve the "Stream has already been operated upon or closed" exception in Java.

www.baeldung.com

 

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함