5

Why does (String/format "%8s" (Integer/toBinaryString 6)) result in a java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object casting exception?

1 Answer 1

8

I don't know Clojure, but I suspect that's trying to call the method as if it were the Java:

String.format("%8s", Integer.toBinaryString(6));

but without the varargs support. I suspect you want:

(String/format "%8s" (into-array Object (Integer/toBinaryString 6)))

See this mailing list thread for more information from people who actually do know Clojure :)

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, this is exactly the issue. A better solution than using String/format and into-array is to just use the Clojure function format, which takes varargs Clojure-style and otherwise behaves the same as String/format.
@amalloy: Indeed, as noted on the mailing list thread. I didn't want to get too far off the track of what I thought I'd be able to get away with in terms of correct code :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.