看到API中出现了这样的注释,这是出于什么考虑?
java.lang.Integer @Deprecated(since = "9")
@Contract(pure = true)
看到API中出现了这样的注释,这是出于什么考虑?
java.lang.Integer @Deprecated(since = "9")
@Contract(pure = true)
@HotSpotIntrinsicCandidate
public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
上面是valueOf, 当你传入小于128的值时,返回的是内置的缓存值,节省空间和效率。