不可变并不意味着
a永远不能等于另一个值。例如,
String也是不可变的,但是我仍然可以这样做:
String str = "hello";// str equals "hello"str = str + "world";// now str equals "helloworld"
str并没有改变,而是变成
str了一个完全新实例化的对象,就像您一样
Integer。因此,的值
a没有发生变化,而是由一个全新的对象代替
newInteger(6)。

不可变并不意味着
a永远不能等于另一个值。例如,
String也是不可变的,但是我仍然可以这样做:
String str = "hello";// str equals "hello"str = str + "world";// now str equals "helloworld"
str并没有改变,而是变成
str了一个完全新实例化的对象,就像您一样
Integer。因此,的值
a没有发生变化,而是由一个全新的对象代替
newInteger(6)。