4 ms·
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
by naruhodo 1y ago
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/ https://www.happycoders.eu/java/main-method/
[2] https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.html#jvms-4.1 https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.h...
[3] https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-2.html#jvms-2.4 https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-2.h...