This should do it:

user=> (defn byte-array? [obj] (= Byte/TYPE (.getComponentType (class obj))))
#'user/byte-array?
user=> (byte-array? (byte-array [(byte 56) (byte 98)]))
true
user=> (byte-array? "")
false
user=> (byte-array? 99)
false

Hope that helps,

Dave

On Sat, Oct 23, 2010 at 11:53 PM, Shantanu Kumar
<[email protected]> wrote:
> Hi
>
> Can anybody tell me how can I detect that a given object is a byte
> array? Or maybe show me how to write a (defn byte-array? [obj] ..)
> function? I want to be able to detect arrays of other types too - e.g.
> char[], Integer[] etc.
>
> I experimented a bit at the REPL:
>
> user=> (type (byte-array [(byte 56) (byte 98)]))
> [B
>
> user=> (supers (type (byte-array [(byte 56) (byte 98)])))
> #{java.lang.Object java.lang.Cloneable java.io.Serializable}
>
> Regards
> Shantanu
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to