2 ms·
If you haven't come across space leaks before, here's a small taste. The program should print the first number of a lazily generated stream: import java.u
by mrkeen 4y ago
If you haven't come across space leaks before, here's a small taste. The program should print the first number of a lazily generated stream:
import java.util.OptionalInt;
import static java.util.stream.IntStream.iterate;
public class Main {
public static void main(String[] args) {
System.out.println(fun().getAsInt());
}
static OptionalInt fun() {
return iterate(0, a -> a + 1)
.flatMap(b ->
iterate(b, c -> c + 1)
.flatMap(d -> iterate(d, e -> e + 1)))
.findFirst();
}
}
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space