use*_*688 4 java caching integer equality object
我一直在阅读关于类的java缓存,我不确定为什么这段代码有效.
Integer x = new Integer(2);
Integer y = new Integer(2);
assert x != y;
assert x.intValue() == y.intValue();
++x;
assert x != y;
assert x.intValue() != y.intValue();
++y;
assert x == y;
assert x.intValue() == y.intValue();
Run Code Online (Sandbox Code Playgroud)
我知道最初x和y不相等,因为它们引用不同的对象,但为什么它们在++之后变得相等?
| 归档时间: |
|
| 查看次数: |
97 次 |
| 最近记录: |