类型转换
int i = 128;
System.out.printin(i);
sout(b);
强制转换 高容量到低容量
自动转换 低到高
注意点:
1.不能转换布尔值
2.不能把对象类型转换为不相干类型
3.在高容量转换为低容量时是强制转换
4.转换时可能出现内存溢出或精度问题
int money = 10_0000_0000;
int years = 20;
int total = money*years; 计算时内存溢出
long total2 = money*((long)years);
sout(total2); 输出正确

浙公网安备 33010602011771号