深入学习java源码之Integer.parseInt()与Integer.valueOf()
一般我们创建一个类的时候是通过new关键字,比如:
Object obj = new Object();
但是对于 Integer 类,我们却可以这样:
Integer a = 128;
为什么可以这样,通过反编译工具,我们可以看到,生成的class文件是:
Integer a = Integer.valueOf(128);
这就是基本数据类型的自动装箱,128是基本数据类型,然后被解析成Integer类。
自动装箱规范要求 byte> 2);
i |= (i >> 4);
i |= (i >> 8);
i |= (i >> 16);
return i - (i >>> 1);
}
public static int lowestOneBit(int i) {
// HD, Section 2-1
return i & -i;
}
public static int numberOfLeadingZeros(int i) {
// HD, Figure 5-6
if (i == 0)
return 32;
int n = 1;
if (i >>> 16 == 0) { n += 16; i > 24 == 0) { n += 8; i > 28 == 0) { n += 4; i > 30 == 0) { n += 2; i > 31;
return n;
}
public static int numberOfTrailingZeros(int i) {
// HD, Figure 5-14
int y;
if (i == 0) return 32;
int n = 31;
y = i 1) & 0x55555555);
i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
i = (i + (i >>> 4)) & 0x0f0f0f0f;
i = i + (i >>> 8);
i = i + (i >>> 16);
return i & 0x3f;
}
public static int rotateLeft(int i, int distance) {
return (i >> -distance);
}
public static int rotateRight(int i, int distance) {
return (i >>> distance) | (i > 1) & 0x55555555;
i = (i & 0x33333333) >> 2) & 0x33333333;
i = (i & 0x0f0f0f0f) >> 4) & 0x0f0f0f0f;
i = (i > 8) & 0xff00) | (i >>> 24);
return i;
}
public static int signum(int i) {
// HD, Section 2-7
return (i >> 31) | (-i >>> 31);
}
public static int reverseBytes(int i) {
return ((i >>> 24) ) |
((i >> 8) & 0xFF00) |
((i
