62,614
社区成员
发帖
与我相关
我的任务
分享
Integer num1 = 100;
Integer num2 = 100;
if (num1 == num2) {
System.out.println("num1 == num2");
}else{
System.out.println("num1 != num2");
}
/*上面的情况,直接分析是引用类型,那么比较的就是引用,理论这样应该是不相等,但是结果却是相等。于是懵逼
然后就当Integer不存在,直接当什么拆箱,然后就是int比较,直接比数字就正确,但是想到上面的情况,于是只能说貌似好有道理。*/
Integer num3 = 200;
Integer num4 = 200;
if (num3 == num4) {
System.out.println("num3 == num4");
}else{
System.out.println("num3 != num4");
}
/*下面的情况,还是按照上面那思路,然后结果相反果断直接晕了,虽然看到书上的解释,但是基本有看没用懂,说什么valueOf(Strings)方法 public static Integer valueOf(String s) throws NumberFormatException {
return Integer.valueOf(parseInt(s, 10));
}接下来继续往后扒 public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
*/
//于是感觉还是参数上的理解问题
你这是Integer中有缓存池的原因喽
你这是Integer中有缓存池的原因喽
[/quote]
你这是Integer中有缓存池的原因喽 Integer num1 = 100;
Integer num2 = 100;
if (num1 == num2) {
System.out.println("num1 == num2");
}else{
System.out.println("num1 != num2");
}
/*上面的情况,直接分析是引用类型,那么比较的就是引用,理论这样应该是不相等,但是结果却是相等。于是懵逼
然后就当Integer不存在,直接当什么拆箱,然后就是int比较,直接比数字就正确,但是想到上面的情况,于是只能说貌似好有道理。*/
Integer num3 = 200;
Integer num4 = 200;
if (num3 == num4) {
System.out.println("num3 == num4");
}else{
System.out.println("num3 != num4");
}
/*下面的情况,还是按照上面那思路,然后结果相反果断直接晕了,虽然看到书上的解释,但是基本有看没用懂,说什么valueOf(Strings)方法 public static Integer valueOf(String s) throws NumberFormatException {
return Integer.valueOf(parseInt(s, 10));
}接下来继续往后扒 public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
*/
//于是感觉还是参数上的理解问题