Can the char type be categorized as an integer?

前端 未结 8 2580
盖世英雄少女心
盖世英雄少女心 2020-12-01 22:32

Just now I read \"char is the only unsigned integral primitive type in Java.\" Does this mean the char is one of the integral types in Java?

Same as in C, recently I

8条回答
  •  渐次进展
    2020-12-01 23:23

    I'm unsure of the formal definition of an integral type, but in short, yes, char is an integral type in Java, since it can be seen as representing an integer.

    You can for instance do

    char c1 = 'a' + 'b';
    
    char c2 = 5;
    
    char c3 = c2 + 3;
    
    int i = c3;
    char c4 = (char) i;
    

    and so on.

提交回复
热议问题