将元数据附加到 Clojure gen-class
是否可以将元数据附加到 Clojure gen 类?
我正在尝试实现一个使用需要向类添加 Java 注释的库的服务器。
从 Chas Emerick 等人即将出版的书“Programming Clojure”(第 9.7.3 节)中,向 gen-class 方法添加注释很容易,但没有提到添加类级别注释。
Is it possible to attach metadata to a Clojure gen-class?
I am trying to implement a server that uses a library that requires Java annotations added to classes.
From Chas Emerick's, et al., forthcoming book "Programming Clojure" (section 9.7.3), adding annotations to gen-class methods is easy, but there is no mention of adding class-level annotations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,我在这里找到了一个很好的例子:
https://github.com/clojure/clojure/blob/master/test/clojure/test_clojure/genclass/examples.clj
这是一些内联代码,因此它不会将来消失:
Yes it is, I found a great example here:
https://github.com/clojure/clojure/blob/master/test/clojure/test_clojure/genclass/examples.clj
Here's some code inlined so it doesn't disappear in the future:
我认为目前这是不可能的。
Rich Hickey 提到在此线程中添加注释支持
https://groups.google.com/group/clojure/browse_thread/thread/d2128e1505c0c117
但据我所知,这仅适用于 deftype / defrecord。我当然可能是错的。
这两个都
无法
为我编译。从例外情况来看,
这似乎是不可能的。
I don't think it is possible at this point.
Rich Hickey mentions adding annotations support in this thread
https://groups.google.com/group/clojure/browse_thread/thread/d2128e1505c0c117
but as far as I can see this is only for deftype / defrecord. I could be wrong of course.
Both of these
and
fail to compile for me. From the exception
It sounds like this is not possible.
要为此添加附加信息,因为我在其他地方找不到它的记录,也可以向构造函数添加注释。
您可以通过将元数据添加到构造函数对的第一个数组来向构造函数添加注释。像这样:
To add additional information to this because I can't find it documented anywhere else it's possible to add annotations to constructors as well.
You can add annotations to constructors by adding meta data to the first array of the constructor pair. Like this: