Skip to content

ClassCastException when casting Character to int #1021

Closed
@omerp

Description

The following code seems to yield different results on Java and in ObjC:

Character c = '\n';
try {
    System.out.println((int) c);
} catch (Exception e) {
    System.out.println(e);
}

Compiling with javac, this yields 10 (correctly), while j2objc throws this exception:

java.lang.ClassCastException: Cannot cast object of type java.lang.Character to JavaLangInteger

Which seems to be due to the fact that unboxing + widening casts are handled for all numeric types except Character (which does not have the intValue/longValue/doubleValue etc. conversion methods).

I'll upload a PR with an attempt to address this issue shortly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions