Clojure的gen-interface中的Java数组

时间:2011-09-23 14:14:12

标签: clojure

我有这段代码:

(ns com.example.main)

(gen-class
  :name com.example.main.CTest
  :methods [ [foo [] "[B"]])

(defn -foo [this]
  (byte-array [(byte 1) (byte 2)]))

(gen-interface
  :name com.example.main.ITest
  :methods [ [foo [] "[B"]])

它正确地在类foo中创建CTest方法,返回类型为byte[]。但是,同样的事情会在[B接口中创建一个返回类型为ITest的方法。我该怎么做呢?这是Clojure中的一个错误吗?

谢谢大卫

1 个答案:

答案 0 :(得分:2)

我不知道是否首选其他解决方案,但这样做有效:

(gen-interface
  :name com.example.main.ITest
  :methods [[foo [] #=(java.lang.Class/forName "[B")]])