For type-hinting #^"[B" works, but for obtaining and passing the class
to defmethod, the best I can come up with is (Class/forName "[B").



On Mar 24, 11:02 am, Frank Siebenlist <frank.siebenl...@gmail.com>
wrote:
> The following repl session shows my attempt to dispatch a multimethod on 
> "type":
>
> ...
> user> (defmulti mm type)
> #'user/mm
> user> (type "a")
> java.lang.String
> user> (defmethod mm java.lang.String [s] (println "string"))
> #<MultiFn clojure.lang.mult...@41e3a0ec>
> user> (mm "a")
> string
> nil
> user> (type (.getBytes "a"))
> [B
> user> (defmethod mm [B [b] (println "bytes"))
> ; Evaluation aborted.
> user> (def ba-type (type (.getBytes "a")))
> #'user/ba-type
> user> (defmethod mm ba-type [b] (println "bytes"))
> #<MultiFn clojure.lang.mult...@41e3a0ec>
> user> (mm (.getBytes "a"))
> bytes
> nil
> user>
> ...
>
> It works easily for the string, but for a native java byte array, type (or 
> class) gives me back this "[B", which I'm unable to use as a dispatch value 
> for the defmethod.
> I can, however, assign the value to a reference and us that to dispatch on 
> successfully - but that feels like a hack.
>
> Is there a way to express the byte array type in a different way than "[B" 
> that would work?
>
> Thanks, Frank.

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to