美文网首页Java
基础数据类型

基础数据类型

作者: 真的有神 | 来源:发表于2022-05-20 00:37 被阅读0次

    Integer.valueOf

    调用 Integer.valueOf 时-128~127 的对象被缓存起来。

    所以在此访问内的 Integer 对象使用==和 equals 结果是一样的。

    如果 Integer 的值一致,且在此范围内,因为是同一个对象,所以==返回 true;但此访问之

    外的对象==比较的是内存地址,值相同,也是返回 false。

    public static Integer valueOf(int i) {

       if (i >= IntegerCache.low && i <= IntegerCache.high)

       return IntegerCache.cache[i + (-IntegerCache.low)];

       return new Integer(i);

    }

    相关文章

      网友评论

        本文标题:基础数据类型

        本文链接:https://www.haomeiwen.com/subject/tmvecctx.html