News for hackers. Stuff that matters.
Re:Public static void main(String[] args) is dead by Panzerschrek on Tuesday September 16, 2025 @01:06AM (#45258211)
So, Java now supports free functions (not associated with some class). Or not really yet?
Re:Public static void main(String[] args) is dead by happymellon on Tuesday September 16, 2025 @01:31AM (#45258372)
They are associated with a class, but the class is basically the file. There are limitations by doing it this way but it is out of preview and officially supported as of Java 25.

https://openjdk.org/jeps/512

Re:Public static void main(String[] args) is dead by ninjin on Tuesday September 16, 2025 @01:18AM (#45258278)
If so, are we observing a move towards Universal Suffrage in the Kingdom of the Nouns? [1]

[1]: https://steve-yegge.blogspot.com/2006/03/execution-in-kingdo...

Re:Public static void main(String[] args) is dead by BinaryRage on Tuesday September 16, 2025 @01:15AM (#45258261)
No, these are just default imports. Module import declarations are in for JDK 25 to make this kind of thing even easier: https://openjdk.org/jeps/511
Re:Public static void main(String[] args) is dead by naruhodo on Tuesday September 16, 2025 @01:31AM (#45258370)
Nope. It's just sugar. [1]

It's somewhat implicit in the JVM spec, but functions are always bound to classes as methods. [2] The only kinds of heap objects you can have a reference to are class instances and arrays. [3]

The lack of free functions is really only a minor inconvenience for language implementers. Clojure, for instance, just compiles new classes to hold functions as methods.

From a programmer's perspective, you can write lambdas, but again, it's just syntactic sugar over an inner class.

[1] https://www.happycoders.eu/java/main-method/ [2] https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.h... [3] https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-2.h...

Re:Public static void main(String[] args) is dead by vincnetas on Tuesday September 16, 2025 @01:14AM (#45258257)
I think all functions are associated with some class. But these classes sometimes are hidden from you and you don't need to know about them. Does that help you? What for would you use true free functions?
Re:Public static void main(String[] args) is dead by throwaway47461 on Tuesday September 16, 2025 @01:15AM (#45258265)
> What for would you use true free functions?

The same things people use free functions for in any other programming language.

Re:Public static void main(String[] args) is dead by rerdavies on Tuesday September 16, 2025 @01:19AM (#45258287)
Cluttering up global namespaces? ;-P
Re:Public static void main(String[] args) is dead by Mawr on Tuesday September 16, 2025 @03:11PM (#45266554)
> What for would you use true free functions?

I'm visibly shaking at this statement. What are you even saying here? A function is the most basic, fundamental unit of code organization. What Java does with its forced classes is a complete perversion of computation, sanity and anything reasonable.

Re:Public static void main(String[] args) is dead by TZubiri on Tuesday September 16, 2025 @01:16AM (#45258273)
Presumably these exist in a Main.java file and the java class is implied. Similarly the string params are also implied, and the non param main() function is just an alias or a wrapper for main(String).

It's just syntactic sugar.