clojure - Clojure:在 Java 对象上调用一系列方法
问题描述
我在某个地方看到过这个文档,但我不记得函数的名称和名称是什么:我正在搜索的是一个函数/宏,它以(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"))
推荐阅读
- c# - Xamarin 在页面之间传递参数
- c# - C# xls & xlsx 查询从工作表中选择,而不考虑工作表名称
- c# - Cortana 是否支持 webhook/调用外部 API?
- php - 内核中的身份验证声明和 laravel 中的路由无法正常工作
- emacs - 如何在 magit 中暂存/提交当前缓冲区?
- java - 从 JDBC 连接到 MSSQL 服务器时出现 Windows 身份验证问题
- java - FLAG_DIM_BEHIND 导致 android oreo 滞后
- kotlin - 需要改进“非常尴尬”的 Rx 逻辑来组合不同的数据源
- javascript - 在 javascript 中拆分和合并 Ranges 数组
- typescript - NestJS GraphQL 数据源