丫的,记不住基本类型啊,还好面试的时候怎么没人问我啊,我擦一顿~![]()
| 用于switch | 基本类型 | 包装类 | 字节 | 取值 |
| 正确,如果包装类需要JDK5.0+ | byte | java.lang.Byte | 1 |
public static final byte MIN_VALUE = -128; public static final byte MAX_VALUE = 127; |
| 正确,如果包装类需要JDK5.0+ | short | java.lang.Short | 2 |
public static final short MIN_VALUE = -32768; public static final short MAX_VALUE = 32767; |
| 正确,如果包装类需要JDK5.0+ | char | java.lang.Character | 2 |
public static final char MIN_VALUE = '\u0000'; public static final char MAX_VALUE = '\uffff'; |
| 正确,如果包装类需要JDK5.0+ | int | java.lang.Integer | 4 |
public static final int MIN_VALUE = 0x80000000; public static final int MAX_VALUE = 0x7fffffff; |
| 不行 | float | java.lang.Float | 4 |
比较独特,是他吗的0 public static final float NaN = 0.0f / 0.0f; |
| 不行 | long | java.lang.Long | 8 |
public static final long MIN_VALUE = 0x8000000000000000L; public static final long MAX_VALUE = 0x7fffffffffffffffL; |
| 不行 | double | java.lang.Double | 8 | public static final double NaN = 0.0d / 0.0; |
| 8 | void | java.lang.Void |
public static final Class TYPE = Class.getPrimitiveClass("void"); 是他吗的本地method,其他class的TYPE都是这么搞的,搞吧,搞死拉到! |
包装类都是final的,所以,你懂的。哦,我懂的。
编译器会对基本类型进行check的,若超过范围,就会throw exception
int i=10000000000000000000000000000000;
// compilation不通过
//e literal 10000000000000000000000000000000 of type int is out of range
自动转换规则:
(byte,short,char)-->int -->long --> float --> double
二、下面看看四舍五入(小学老师总扯这东西,舍舍的,一切都是浮云,神马东西!
)
public final strictfp class Math{
private Math() {}
}
public static int round(double a) {
return (int)floor(a + 0.5f);
}
public static double floor(double a) {
return StrictMath.floor(a); // 返回小于等于参数值的最大整数
}
public final strictfp class StrictMath {
public static native double floor(double a);
}
strict float point (精确浮点) strictfp,必须符合IEEE-754标准
4舍5入的规则:
小于等于参数值+0.5的最大整数
PS:暂时写到这里,改天补充!!刚吃了块蛋糕,2个樱桃,一个草莓,2瓣鸭梨。烧心ing![]()

被折叠的 条评论
为什么被折叠?



