Hi David,
On Sun, Nov 22, 2009 at 6:55 PM, David Brown <[email protected]> wrote:
> java.nio.channels.FileChannel contains some .write methods:
>
> [27] write : int (ByteBuffer)
> [28] write : int (ByteBuffer,long)
> [29] write : long (ByteBuffer[])
> [30] write : long (ByteBuffer[],int,int)
>
> I have an array of ByteBufers, but I can't figure out how to call #29
> without it being a reflecting call. Giving a type of #^objects
> doesn't seem to help.
>
> (defn foo [#^FileChannel chan, bufs]
> (.write chan (to-array bufs)))
>
> gives a reflection warning.
>
> Any ideas?
Yup:
(defn foo [#^FileChannel chan, bufs]
(.write chan #^"[Ljava.nio.ByteBuffer;" (to-array bufs)))
#^objects is a shortcut for hinting Object[] instances.
When you want to hint an instance of some.Class[], the hint is #^"[Lsome.Class;"
So #^objects is short for #^"[Ljava.lang.Object;".
If you can't remember the syntax, you can try this at the repl:
user=> (class (into-array ByteBuffer nil))
[Ljava.nio.ByteBuffer;
hth,
Christophe
--
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (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