Reputation: 4651
So far I found two ways to call static methods from Java as functions in Clojure.
;; using .
(. Math min 12 13)
;; using /
(Math/min 12 13)
The calls can become more complicated when using return-values of one call, for the next call.
(. (. System out) println "Static call from Clojure.")
It seems to not work using the "/" notation:
((System/out) /println "Static call from Clojure.")
Probably the "."-notation is meant to handle this kind of method-calls. In my opinion the "."-notation becomes difficult to read even when there are only two method calls in a row.
Is there a clearer way to call methods in a row?
Upvotes: 1
Views: 165
Reputation: 20245
Are you aware of this notation?
(.. System (getProperties) (get "os.name"))
Notice the two dots.
Which will expand to:
(. (. System (getProperties)) (get "os.name"))
Java Interop on Clojure.org.
Upvotes: 4
Reputation: 32488
Try following.
(-> (System/out) (.println "Static call from Clojure."))
Upvotes: 1