类型变换
/*
123 是属于int类型
x是属于int类型的变量
当123int类型的字面值赋值给int类型的变量x不存在类型转换
*/
int x=123;
System.out.prinln(x);
/*
456是int类型的字面值
y是long类型的变量
int类型是小容量
long类型是大容量
当456int类型的值赋值给long类型是小容量到大容量是自动转换
*/
long y=456;
System.out.prinln(y);
/*
2147483648大于int最大值2147483647
所以会赋值失败
错误: 过大的整数: 21474836484.0.3336ava
*/
long z=2147483648;
System.out.prinln(z);
/*
编译不会报错,运行可能损失精度
*/
byte a=123;
System.out.println(a);
/*
编译会报错,报错信息提示损失精度
加上强制类型转换符
*/
byte b=(byte)128;
System.out.println(b);
//编译不会报错,运行提示损失精度
short c=32767;
System.out.println(c);
//编译会报错因超出了short的最大值32768所以需要加上强制类型转换符
short d=32769;
System.out.println(d);
//编译不会报错没有超出char的最大值65535
char e=65535;
System.out.println(e);
//65536超出了char的最大值会编译报错加上强制类型转换符就编译通过,但是运行提示可能会损失精度。
char f=(char)65536;
System.out.println(f);
【SUN公司提供的字面值为int类型时赋值给byte,short,char数据类型的时候只要不超过他们的最大值都可以直接赋值,如果超出看就需要加强制类型转换符就会编译通过,编译通过运行提示损失精度一般不用强制类型转换】
                    
                
                
            
        
浙公网安备 33010602011771号