public class 常量池_byte {
public static void main(String[] args) {
/**
* byte范围内的值(-128 ~ 127) 在常量池中存在
*/
Integer i1 = 127;
Integer i2 = 127;
System.out.println(i1 == i2); // true
System.out.println(i2.equals(i2)); // true
Integer i3 = 128;
Integer i4 = 128;
System.out.println(i3 == i4); // false
System.out.println(i3.equals(i4)); // true
Integer i5 = new Integer(127);
Integer i6 = new Integer(127);
System.out.println(i5 == i6); // false
System.out.println(i5.equals(i6)); // true
}
}
|
|