1

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?

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Try following.

(-> (System/out) (.println "Static call from Clojure."))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.