Clojure:在 Java 对象上调用一系列方法

Mic*_*ael 3 clojure clojure-java-interop

我在某处看到过这个文档,但我不记得函数的名称和名称:我正在搜索的是一个函数/宏,它以(Java)对象作为参数,在该对象上执行一系列方法,然后返回它。类似的东西:

(<the function> obj
  (.setName obj "the name")
  (.setAmount obj42.0)
  ; ...
  (.setDescription obj "the description"))  ; returns the updated obj
Run Code Online (Sandbox Code Playgroud)

Lee*_*Lee 5

您可以使用..

(.. obj (setName "the name") (setAmount 42.0) ... (setDescription "the description"))
Run Code Online (Sandbox Code Playgroud)

如果这些方法不返回目标对象,您可以使用doto

(doto obj (.setName "the name") (.setAmount 42.0) ... (.setDescription "the description"))
Run Code Online (Sandbox Code Playgroud)