简体   繁体   English

如何获取由Clojure中的gen-class生成的Class

[英]how to get the Class generated by gen-class in clojure

I am using some java lib which require the access the class generated by gen-class 我正在使用一些Java库,需要访问由gen-class生成gen-class

(ns cljfx.test
  (:import some.java.Lib))

(gen-class :name Main)

(defn -main [& arg]
  (Lib/method-require-class-arg (classOf Main)))

the prototype of method-require-class-arg is method-require-class-arg的原型是

public static void method-require-class-arg(Class someClass) {
  // ...
}

How to write the (classOf Main) part in the first snippet? 如何在第一个代码片段中编写(classOf Main)部分?

Your gen-class example is incorrect. 您的gen-class示例不正确。 If you use 如果您使用

(gen-class :name cljfx.test.Main)

then just cljfx.test.Main will return the Class object. 然后cljfx.test.Main将返回Class对象。

You can use Class/forName method. 您可以使用Class/forName方法。

Ex: (Class/forName "java.lang.String") 例如: (Class/forName "java.lang.String")

In your case it should be (Class/forName "Main") and you need to make sure you enable aot in your project.clj 在您的情况下,它应该是(Class/forName "Main")并且您需要确保在project.clj中启用了aot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM