all 10 comments

sorted by: hot top controversial new old
[–] 9 points 1 year ago (8 children)

You mean this?

Now Java supports top-level instance main methods and class-less compact files. That means now the following declaration is valid:

void main() {
    System.out.println("Hello from Java 25!");
}
  • source
  • hideshow 8 child comments
  • [–] 4 points 1 year ago (3 children)

    I enjoy that the monstrous System.out.println is still right below. 🙃

  • source
  • parent
  • hideshow 3 child comments
  • [–] 4 points 1 year ago* (last edited 1 year ago) (2 children)

    If you import java.lang.IO.println statically, you can simply write println

    import static java.lang.IO.println;
    
    static void main() {
      println("Hello, World!");
    }
    
  • source
  • parent
  • hideshow 2 child comments
  • [–] 3 points 1 year ago (1 child)

    Ah, interesting. I haven't kept up with the newest Java changes, so you kind of answered that backwards for me. Being able to just use IO.println() is already pretty good and for sure what I'd prefer over having to add an import. Seems to also be a new addition in Java 25, so I guess, Hello World looks a lot different all of a sudden.

    Also interesting that this kind of static import doesn't work with System.out.println, I'm guessing because out is already a field of System rather than a package or type. It can be used to write it as out.println, but yeah, not much of a point anymore when IO.println exists.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 1 year ago

    Ah, interesting. I haven't kept up with the newest Java changes, so you kind of answered that backwards for me. Being able to just use IO.println() is already pretty good and for sure what I'd prefer over having to add an import. Seems to also be a new addition in Java 25, so I guess, Hello World looks a lot different all of a sudden.

    My code was merely a demonstration that just println is possible now. Like you, I'd prefer IO.println in "real" code. My bar for static imports is extremely high.

    Also interesting that this kind of static import doesn't work with System.out.println, I'm guessing because out is already a field of System rather than a package or type. It can be used to write it as out.println, but yeah, not much of a point anymore when IO.println exists.

    Static imports are only for static fields and methods. System.out::println is an instance method.

  • source
  • parent
  • [–] 2 points 1 year ago (2 children)

    I'll be honest, I don't get the point of this feature. It's nice for beginners or for writing small, quick, programs...but for the overwhelming majority of all java code I don't see it being useful

  • source
  • parent
  • hideshow 2 child comments
  • [–] 3 points 1 year ago

    the trend of serverless means that people are writing a ton more programs that are smallish single endpoint things. not that a ton of people are using java there, but that was a major motivation for c#

  • source
  • parent
  • [–] 3 points 1 year ago

    Sure, but I think the argument in favor of this feature is that the overwhelming majority of people picking up programming for the first time tend to be beginners, so if it helps them learn the basics before having to grapple with OOP then it is worthwhile.

  • source
  • parent
  • Oh come on, please don't kill the public static void main(string args) meme!

  • source