News for hackers. Stuff that matters.
Re:Java string interpolation feature has been cancelled by MeetingsBrowser on Thursday June 20, 2024 @02:45PM (#40741859)
maybe I misunderstood

> so far I've been able to produce an infinite-loop or stack/heap space problem

The linked issue was resolved 5 years ago

Re:Java string interpolation feature has been cancelled by mrkeen on Tuesday June 25, 2024 @05:53AM (#40786471)
Haha I bet it was! "Java great" according to Java.

Anyway, it's a been a while, so, I downloaded the latest Adoptium - that's the one you don't get sued for using right?

  ./javac --version
  javac 21.0.3
Full source code for pulling the first number out of a big stream:

  import java.util.stream.Stream;

  public class Main {
      public static void main(String[] args) {
          Stream.iterate(0, a -> a + 1)
                .flatMap(b -> Stream.iterate(b, c -> c + 1)
                                    .flatMap(d -> Stream.iterate(d, e -> e + 1)))
                .limit(1L)
                .findFirst()
                .get();
      }
  }
Run it:

  ./javac Main.java && time ./java Main

  Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.base/java.lang.Integer.valueOf(Integer.java:1073)
    at Main.lambda$main$2(Main.java:7)
    {...}
    at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
    at Main.main(Main.java:9)

  real 0m9,911s
  user 1m31,992s
  sys 0m1,423s