gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 15:15:44 24 4
gpt4 key购买 nike

我在某处看到过这个文档,但我不记得该函数的名称在哪里以及是什么:我正在搜索的是一个函数/宏,它采用(Java)对象作为参数,在其上执行一系列方法该对象并返回它。类似这样的事情:

(<the function> obj
(.setName obj "the name")
(.setAmount obj42.0)
; ...
(.setDescription obj "the description")) ; returns the updated obj

最佳答案

您可以使用..:

(.. obj (setName "the name") (setAmount 42.0) ... (setDescription "the description"))

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

(doto obj (.setName "the name") (.setAmount 42.0) ... (.setDescription "the description"))

关于Clojure:在 Java 对象上调用一系列方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52296556/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com