> How do you call a method which accepts Object arguments?
> 
> String/format | 
> http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#format(java.lang.String,
>  java.lang.Object...)
> 
> user=> (String/format "%s" "foo")
> ClassCastException java.lang.String cannot be cast to [Ljava.lang.Object;  
> user/
> eval668 (NO_SOURCE_FILE:1)


String/format takes a variable number of arguments in Java. At the JVM level, 
that's represented as an array of Objects.

The JVM level class name for an array of objects is shown in the exception: 
[Ljava.lang.Object

Here's an example of calling String/format correctly:

https://github.com/clojure/clojure/blob/clojure-1.6.0/src/clj/clojure/core.clj#L5284

(String/format fmt (to-array args)

In the case of String/format itself it may be easier to call 
clojure.core/format instead, but the same pattern applies elsewhere.

If you need an array whose elements have a type more specific than Object, use 
clojure.core/into-array.

--Steve

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to