diff --git a/docs/java/Java疑难点.md b/docs/java/Java疑难点.md index e13c982b..8abad01b 100644 --- a/docs/java/Java疑难点.md +++ b/docs/java/Java疑难点.md @@ -78,7 +78,7 @@ System.out.println(x == y);// true Integer a = new Integer(3); Integer b = new Integer(3); System.out.println(a == b);//false -System.out.println(a.equals(b));//false +System.out.println(a.equals(b));//true ``` 当使用自动装箱方式创建一个Integer对象时,当数值在-128 ~127时,会将创建的 Integer 对象缓存起来,当下次再出现该数值时,直接从缓存中取出对应的Integer对象。所以上述代码中,x和y引用的是相同的Integer对象。