Method values in Clojure are, well, values, by themselves. It's syntax sugar for creating a lambda function that uses the right overload of a Java method.
Method references in Java are a syntax sugar to create the right thing in a particular context where it's used. You can't just get a value of LocalDate::from
- you have to put it in a context where Java compiler can figure out what you want exactly.
Your example is more about Java, not Clojure. It's Java compiler that figures out all the signatures and that they're compatible and makes it possible to use ...::from
that way.
Since you're just calling the parse
function, it doesn't make much sense to use
(^[CharSequence TemporalQuery] DateTimeFormatter/parse formatter x y)
when instead you can use
(.parse ^DateTimeFormatter formatter ^CharSequence x ^TemporalQuery y)
However, it won't help in your case because LocalDate/from
is not an instance of TemporalQuery
. In Clojure, LocalDate/from
is a regular Clojure function. Even if you use ^[TemporalAccessor] LocalDate/from
, it's still a regular Clojure function, just pointing to the .../from
method (not important here since there's only one such method in LocalDate
, but is important when there are overloads). That function's signature is still [Object]
. (And even if the signature was [TemporalQuery]
, I doubt that would help since Java compiler won't be called here, but I could be wrong.)
With all that said, I'm pretty sure that with the current state of affairs the only way to achieve what you want is via the good old reify
:
(let [formatter java.time.format.DateTimeFormatter/BASIC_ISO_DATE]
(.parse formatter
"20200202"
(reify java.time.temporal.TemporalQuery
(queryFrom [_ ^java.time.temporal.TemporalAccessor temporal]
(java.time.LocalDate/from temporal)))))