在相关说明中,如果您想为一组原语查找 Java Class 对象,您可以使用命名空间中的tupelo.types
这个技巧:
; An instance of the java.lang.Class<XXXX[]> (e.g. java.lang.Class<Byte[]>).
(def ^:private class-boolean-array (.getClass (boolean-array 0)))
(def ^:private class-byte-array (.getClass (byte-array 0)))
(def ^:private class-char-array (.getClass (char-array 0)))
(def ^:private class-double-array (.getClass (double-array 0)))
(def ^:private class-float-array (.getClass (float-array 0)))
(def ^:private class-int-array (.getClass (int-array 0)))
(def ^:private class-long-array (.getClass (long-array 0)))
(def ^:private class-object-array (.getClass (object-array 0)))
(def ^:private class-short-array (.getClass (short-array 0)))
这用于类型测试,例如:
(defn boolean-array?
"Returns true is the arg is a boolean array, else false."
[arg]
(= class-boolean-array (.getClass arg)))