Welcome! Please see the About page for a little more info on how this works.

0 votes
in Errors by

Observed behaviour

`
(int "0") =>
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Character

Expected behaviour
(int "0") =>
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
or
IllegalArgumentException
`

6 Answers

0 votes
by

Comment made by: jafingerhut

If someone wants to improve the behavior of int in this case, they should also consider similar improvements to the error messages for unchecked-int, char, and unchecked-char.

0 votes
by

Comment made by: michael-drogalis

Patch improved-int-char-casting-error-messages.diff on January 6, 2013.

0 votes
by

Comment made by: alexmiller

{{int}} knows how to coerce numbers and chars to ints. It does not currently support Strings. It would be worthwhile to either add this behavior or make int's docstring more descriptive than just "Coerce to int".

0 votes
by

Comment made by: michael-drogalis

string-coerce-to-int.diff
September 4th, 2013
Fixes int and char casting error messages, and allows casting from String to int as Alex Miller suggested.

0 votes
by

Comment made by: michael-drogalis

Notably, (map int (link: "1" "2" "3")) fails with "ClassCastException java.lang.String cannot be cast to java.lang.Character" using this patch.
It emanates from RT.java from intCast(Object). So it looks like the Strings are losing their types when they're being mapped over.
I would guess this is intentional?

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1030 (reported by alex+import)
...