clojure - 将元数据附加到 Clojure gen-class

标签 clojure annotations gen-class

是否可以将元数据附加到 Clojure gen-class?

我正在尝试实现一个使用需要向类添加 Java 注释的库的服务器。

从 Chas Emerick 等人即将出版的“Programming Clojure”一书(第 9.7.3 节)中,向 gen-class 方法添加注释很容易,但没有提到添加类级别的注释。

最佳答案

是的,我在这里找到了一个很好的例子:

https://github.com/clojure/clojure/blob/master/test/clojure/test_clojure/genclass/examples.clj

这是内联的一些代码,因此将来不会消失:

(gen-class :name ^{Deprecated {}
                   SuppressWarnings ["Warning1"] ; discarded
                   java.lang.annotation.Target []}
                 clojure.test_clojure.genclass.examples.ExampleAnnotationClass
           :prefix "annot-"
           :methods [[^{Deprecated {}
                        Override {}} ;discarded
                      foo [^{java.lang.annotation.Retention java.lang.annotation.RetentionPolicy/SOURCE
                             java.lang.annotation.Target    [java.lang.annotation.ElementType/TYPE
                                                             java.lang.annotation.ElementType/PARAMETER]}
                           String] void]])

关于clojure - 将元数据附加到 Clojure gen-class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7703467/

相关文章:

clojure - gen-class 不生成类

macros - 使用 gen-class 的 clojure 宏不会创建注释

clojure - 在中间件阶段访问路由参数

Clojure Spec vs Typed vs Schema

ios - Swift 3.0 注释取消标注

java - 如何使用 hibernate/jpa 注释将一个类映射到不同的表

clojure - 为什么 LET 不适用于 VECTOR?

Clojure:resolve 和 var 有什么区别?

php - API 平台 : Change description of an endpoint