char and int in Java

A char can be automatically converted to an int. See JLS 5.1.2:

The following 19 specific conversions on primitive types are called the widening primitive conversions:

  • char to int, long, float, or double

A widening conversion of a signed integer value to an integral type T simply sign-extends the two’s-complement representation of the integer value to fill the wider format. A widening conversion of a char to an integral type T zero-extends the representation of the char value to fill the wider format.

(emphasis added)

Leave a Comment