On Sat, Nov 7, 2009 at 10:41 AM, David Brown <cloj...@davidb.org> wrote:
>
> I can't figure out how to avoid reflection, in the 'update' method of
> MessageDigest.  It is overloaded on a single argument with either
> 'byte', 'byte[]', or 'java.nio.ByteBuffer'.
>
>   (import '(java.security MessageDigest))
>   (set! *warn-on-reflection* true)
>
> The compiler didn't seem to like a tag that wasn't actually a class
> name:
>
>   (def byte-array-class
>     (class (make-array Byte/TYPE 0)))
>
>   ;; "Unable to resolve classname: byte-array-class"
>   (defn update1
>     [#^MessageDigest md #^{:tag byte-array-class} item]
>     (.update md item))

Right, :tag values should be symbols, not classes or instances of
those classes.  Most of those symbols name actual Java classnames
but a few other symbols are supported, mostly for arrays of
primitives:

  objects      Object[].class;
  ints         int[].class;
  longs        long[].class;
  floats       float[].class;
  doubles      double[].class;
  chars        char[].class;
  shorts       short[].class;
  bytes        byte[].class;
  booleans     boolean[].class;

This should work:

    (defn update1 [#^MessageDigest md, #^bytes item]
      (.update md item))

--Chouser

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to