开发者

Why Is String Formatting Causing a Casting Exception?

开发者 https://www.devze.com 2023-04-10 04:20 出处:网络
Why does (String/format \"%8s\" (Integer/toBinaryString 6)) result in a java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Ob开发者_运维技巧ject casting exception?I don\'t kn

Why does (String/format "%8s" (Integer/toBinaryString 6)) result in a java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Ob开发者_运维技巧ject casting exception?


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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消