type casting of byte and int

后端 未结 8 1042
-上瘾入骨i
-上瘾入骨i 2021-01-27 16:27

I\'d a code snippet:

class AutoTypeCast{
    public static void main(String...args){
        int x=10;
        byte b=20;//no compilation error
        byte c=x;         


        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-27 17:01

    20 always can be represented by a byte, while x, which according to the compiler can be any integer, may be too large to be represented by a byte.

提交回复
热议问题