Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure :: (String/format "%s" "a") :: fails with ClassCastException

Tags:

clojure

The following call:

(String/format "%s" "a")

... throws a "ClassCastException java.lang.String cannot be cast to [Ljava.lang.Object" exception in Clojure.

(String/format "%s" (cast Object "a"))

.... produces the same exception.

like image 829
Marcus Junius Brutus Avatar asked Jan 14 '13 16:01

Marcus Junius Brutus


1 Answers

Because last argument in java API is array Object[] instead of Object.

Just call (String/format "%s" (into-array ["a"]))

But more idiomatic to use (format "Hello %s" "world")

like image 116
mishadoff Avatar answered Oct 04 '22 06:10

mishadoff