类型转换由低到高:
byte、short、char => int => long => float => doouble
不能对布尔值进行转换
- 在高容量转换到低容量时,需要强制转换
- 转换的时候可能存在内存溢出或精度问题
int i = 128;
byte j = (byte)i; //-128 内存溢出
System.out.println((int)23.7); //23
System.out.println((int)-45.7f); //-45
//JDK7新特性
int money = 10_0000_0000;
int years = 20;
int total = money*years;
System.out.println(total); //负数 内存溢出 需要使用long型
long total = (long)money*(long)years;