类型 | boolean | byte | char | short | int | long | float | double |
封装类型 | Boolean | Byte | Character | Short | Integer | Long | Float | Double |
Bit | 1 | 8 | 16 | 16 | 32 | 64 | 32 | 64 |
基本类型在java结构中都是固定的,这样有利于跨平台对数据在内存中储存有个标准。
要注意强制转换时的精度丢失问题:double b = 10.0d; int a = (int) b; 低类型向高类型转换有可能产生精度丢失,还要注意运算时,编译器会自动提升类型,如short c = 1, int a = c+2;byte、short、char、int计算时自动提升为int类型计算。还有注意常量池问题:Integer i = 120; Integer i2 = 120; system.out.print( i == i2 ) 输出为true,因为Integer内部维护了一个常量池。在-128 - 127 之间。