public static void main(String[] args) {
Integer i = new Integer(10);
Integer j = new Integer(10);
if (i == j){
System.out.println("相等");
}else {
System.out.println("不相等");
}
Integer a = 10;
Integer b = 10;
if (a == b){
System.out.println("相等");
}else {
System.out.println("不相等");
}
Integer m = 128;
Integer n = 128;
if (m==n){
System.out.println("相等");
}else {
System.out.println("不相等");
}
}
当new一个对象时就是创建一个空间,两个对象地址不相同。当在-127和127之间时,默认使用int方式复制,超过整个区间则会创建对象