public static Integer
valueOf(int i)
{ return i
>= 128 ||
i < -128 ? new Integer(i)
: SMALL_VALUES[i + 128]; }
本文详细介绍了Java中Integer对象的缓存机制。当Integer对象的值在-128到127之间时,会从预定义数组SMALL_VALUES中返回缓存的对象,从而避免了多次创建相同值的对象。对于超出此范围的整数值,则会创建新的Integer实例。
public static Integer
valueOf(int i)
{ return i
>= 128 ||
i < -128 ? new Integer(i)
: SMALL_VALUES[i + 128]; }
被折叠的 条评论
为什么被折叠?
