Java?????????????
???????????? ???????[ 2016/3/1 11:01:44 ] ??????????????? ???????????
?????????????Java??Integer??????????????????Java 5????????????????????楨???????????????????????Integer??????????????????仺????????????????????????????????????????????????3??????Java????????????????????????????????????????????ú???????????
package com.javapapers.java;
public class JavaIntegerCache {
public static void main(String... strings) {
Integer integer1 = 3;
Integer integer2 = 3;
if (integer1 == integer2)
System.out.println("integer1 == integer2");
else
System.out.println("integer1 != integer2");
Integer integer3 = 300;
Integer integer4 = 300;
if (integer3 == integer4)
System.out.println("integer3 == integer4");
else
System.out.println("integer3 != integer4");
}
}
????????????????????????ж????????false???????????????????????????????????????????ò??????????????????if?ж????false?????Java?У?==???????????????equals????????????????????????У??????????в?????????????????б????????????false??????????????????????if?????ж??????????????
??????????δ?????????????????
????integer1 == integer2
????integer3 != integer4
????Java??Integer????????
??????Java 5?У???Integer?????????????????1?????????????????????????????????????????????????????????á?
???????????????????-128 ?? +127??
???????????????????ù??????????????????á?
????Java???????????????????????????????????????????????????????valueOf??????
????Integer a = 10; //this is autoboxing
????Integer b = Integer.valueOf(10); //under the hood
?????????????????????????????????????????????????????????JDK?е?valueOf????????????JDK 1.8.0 build 25??????
/**
* Returns an {@code Integer} instance representing the specified
* {@code int} value. If a new {@code Integer} instance is not
* required?? this method should generally be used in preference to
* the constructor {@link #Integer(int)}?? as this method is likely
* to yield significantly better space and time performance by
* caching frequently requested values.
*
* This method will always cache values in the range -128 to 127??
* inclusive?? and may cache other values outside of this range.
*
* @param i an {@code int} value.
* @return an {@code Integer} instance representing {@code i}.
* @since 1.5
*/
public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
??????????????????IntegerCache.cache??????????????????new???????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11