Java char is also an int?

前端 未结 7 1810
甜味超标
甜味超标 2020-12-04 02:12

I was trying to get some code done for class:

public int getValue(char value) {
    if (value == \'y\') return this.y;
    else if (value == \'x\') return th         


        
7条回答
  •  情书的邮戳
    2020-12-04 02:26

    A char is not an int. However, it is an integral type. That is to say, it's considered to be a whole number that can be converted to and from other integral types (long,short,byte and int), according to the Java Language Specification.

    Basically what this means is that it is assignment-compatible to int. Its value is between 0 and 65535, and if you assign it to an int or cast it to an int and print it, you'll get the UTF-16 value of the character it represents.

提交回复
热议问题