Integer的自动拆包

思考:
public class A{
public static Integer age=new Integer(0);
public static void main(String [] args){
add(age);
syso(age);----->B
}
public static void add(int a){
a++;
}
}
A 0
B 1   
c 2
d 3
new Integer(0)==new Integer(0)---->false
(new Integer(0))+1 ---->
System.out.println((new Integer(0)+1)==(new Integer(0)+1));//true   1==1
System.out.println(new Integer(0)==new Integer(0));//false  0x0001 ==0x0002

对于包装数据类型而言,只要遇到运算符号就会变成基本数据类型中的值------------>自动拆包

Integer  i=new Integer(0);  i--->0
int a=i+1;

猜你喜欢

转载自blog.csdn.net/zgl1243094406/article/details/79825003
今日推荐