Clojure 1.12.0-alpha10
Clojure 1.12.0-alpha10 is now available! Find download and usage information on the Downloads page. Method values Clojure programmers often want to use Java methods in higher-order functions (e.g. passing a Java method to map ). Until now, programmers have had to manually wrap methods in functions. This is verbose, and might require manual hinting for overload disambiguation, or incur incidental reflection or boxing. Programmers can now use Java qualified methods as ordinary functions in value contexts - the compiler will automatically generate the wrapping function. New in this release: the compiler will generate a reflective call when a qualified method does not resolve due to overloading. Developers can supply :param-tags metadata on qualified methods to specify the signature of a single desired method, 'resolving' it. New in this release: the compiler will generate a reflective call when param tags are not supplied on a qualified method that does not resolve due to overloading. See: CLJ-2793 , CLJ-2844 , CLJ-2835 Qualified methods - Class/method , Class/.method , and Class/new Java members inherently exist in a class. For methods as values we need a way to explicitly specify the class of an instance method because there is no possibility for inference. Qualified methods have value semantics when used in non-invocation positions: Classname/method - value is a Clojure function that invokes a static method Classname/.method - value is a Clojure function that invokes an instance method Classname/new - value is a Clojure function that invokes a constructor New in this release: developers must

Clojure 1.12.0-alpha10 has been released, bringing significant improvements to how Clojure programmers can work with Java methods. This new version introduces the ability to use Java qualified methods as ordinary functions in value contexts, eliminating the need for manual wrapping and reducing verbosity. The compiler now automatically generates the necessary wrapping function, which simplifies the process of using Java methods in higher-order functions, such as passing a Java method to map.
One of the key features of this release is the handling of overloading. Previously, programmers had to manually disambiguate overloaded methods, which could be time-consuming and error-prone. In Clojure 1.12.0-alpha10, the compiler generates a reflective call when a qualified method does not resolve due to overloading. This means that the compiler can automatically determine the correct method based on the provided arguments, reducing the likelihood of errors and improving efficiency.
To further enhance the resolution of overloaded methods, developers can now supply :param-tags metadata on qualified methods. These tags allow programmers to specify the signature of a single desired method, effectively resolving the overloading issue. If param tags are not supplied on a qualified method that does not resolve due to overloading, the compiler will generate a reflective call. This feature ensures that developers can work with Java methods in a more intuitive and efficient manner.
Qualified methods in Clojure have value semantics when used in non-invocation positions. For example, Classname/method represents a Clojure function that invokes a static method, Classname/.method represents a function that invokes an instance method, and Classname/new represents a function that invokes a constructor. These notations provide a clear and concise way to reference Java methods within Clojure code.
In this release, developers must use the Classname/method and Classname/.method syntax to differentiate between static and instance methods. This change ensures that the Clojure compiler can correctly resolve the intended method, whether it is static or instance-based.
Qualified method invocations with param-tags rely solely on the tags to resolve the method. Without param-tags, they behave like the equivalent dot syntax, with the qualifying class taking precedence over hints of the target object and over its runtime type when invoked via reflection. This feature allows for more flexible and efficient method resolution in Clojure.
Clojure 1.12.0-alpha10 is available for download and detailed usage information can be found on the Downloads page. This release represents a significant step forward in simplifying the integration of Java methods into Clojure code, making it easier for developers to leverage Java's extensive libraries and frameworks while maintaining the clarity and expressiveness of Clojure. As Clojure continues to evolve, these improvements will undoubtedly enhance the productivity and efficiency of Clojure programmers working with Java interoperability.










