简体   繁体   中英

How to call several (static) Java-methods in a row in Clojure

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?

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.

请尝试以下。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM