What\'s the best way to detect whether an object is a Java primitive array in Clojure?
The reason I need this is to do some special handling for primitive arrays, which
As pointed by Arthur Ulfeldt, you can use Class/forName
, for example, like here:
(def byte_array_class (Class/forName "[B"))
(defn byte-array? [arr] (instance? byte_array_class arr))
If you want to avoid magic strings like "[B"
when caching the classes, you can apply class
to an existing array object:
(def byte_array_class (class (byte-array [])))