-128----127缓存,在栈中获取

2023-10-30

</pre><span style="font-size: 13.3333px;">package test;</span><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">import java.util.HashMap;</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">import java.util.HashSet;</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">import java.util.Map;</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">import java.util.Set;</span><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">import org.apache.commons.logging.Log;</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">import org.apache.commons.logging.LogFactory;</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">import org.slf4j.Logger;</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">import org.slf4j.LoggerFactory;</span><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">public class Test {</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">/*</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;"> * 看程序写结果</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;"> * </span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;"> * 注意:Integer的数据直接赋值,如果在-128到127之间,会直接从缓冲池里获取数据</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;"> */</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">    public static void main(String[] args) {</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        Integer i1 = new Integer(127);</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        Integer i2 = new Integer(127);</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        System.out.println(i1 == i2);</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        System.out.println(i1.equals(i2));</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        System.out.println("-----------");</span><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        Integer i3 = new Integer(128);</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        Integer i4 = new Integer(128);</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        System.out.println(i3 == i4);</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        System.out.println(i3.equals(i4));</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        System.out.println("-----------");</span><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        Integer i5 = 128;</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        Integer i6 = 128;</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        System.out.println(i5 == i6);</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        System.out.println(i5.equals(i6));</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        System.out.println("-----------");</span><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        Integer i7 = 127;</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        Integer i8 = 127;</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        System.out.println(i7 == i8);</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        System.out.println(i7.equals(i8));</span><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        // 通过查看源码,我们就知道了,针对-128到127之间的数据,做了一个数据缓冲池,如果数据是该范围内的,每次并不创建新的空间</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">        Integer ii = Integer.valueOf(127);</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px; white-space: pre;">	</span><span style="font-size: 13.3333px;">    }</span><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><br style="font-size: 13.3333px;" /><p><span style="font-size: 13.3333px;">}</span></p><p><span style="font-size: 13.3333px;">public static Integer valueOf(int i) {</span></p><span style="font-size: 13.3333px;">        assert IntegerCache.high >= 127;</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">        if (i >= IntegerCache.low && i <= IntegerCache.high)</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">            return IntegerCache.cache[i + (-IntegerCache.low)];</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">        return new Integer(i);</span><br style="font-size: 13.3333px;" /><span style="font-size: 13.3333px;">    }</span><pre>
package test;


import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;




public class Test {

/*
 * 看程序写结果
 * 
 * 注意:Integer的数据直接赋值,如果在-128到127之间,会直接从缓冲池里获取数据
 */
    public static void main(String[] args) {
        Integer i1 = new Integer(127);
        Integer i2 = new Integer(127);
        System.out.println(i1 == i2);
        System.out.println(i1.equals(i2));
        System.out.println("-----------");


        Integer i3 = new Integer(128);
        Integer i4 = new Integer(128);
        System.out.println(i3 == i4);
        System.out.println(i3.equals(i4));
        System.out.println("-----------");


        Integer i5 = 128;
        Integer i6 = 128;
        System.out.println(i5 == i6);
        System.out.println(i5.equals(i6));
        System.out.println("-----------");


        Integer i7 = 127;
        Integer i8 = 127;
        System.out.println(i7 == i8);
        System.out.println(i7.equals(i8));


        // 通过查看源码,我们就知道了,针对-128到127之间的数据,做了一个数据缓冲池,如果数据是该范围内的,每次并不创建新的空间
        Integer ii = Integer.valueOf(127);
    }


} public static Integer valueOf(int i) {
        assert IntegerCache.high >= 127;
        if (i >= IntegerCache.low && i <= IntegerCache.high)
            return IntegerCache.cache[i + (-IntegerCache.low)];
        return new Integer(i);
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

-128----127缓存,在栈中获取 的相关文章

随机推荐

  • DevEco Studio 3.1差异化构建打包,提升多版本应用开发效率

    原文 DevEco Studio 3 1差异化构建打包 提升多版本应用开发效率 点击链接查看更多技术内容 HUAWEI DevEco Studio是开发HarmonyOS应用及服务的一站式集成开发环境 本次分享DevEco Studio 3
  • vue使用高德地图为信息窗体再添加点击事件

    即使是用的vue 也不能使用 click为窗体添加点击事件 需要使用onclick 并且在定义了函数后 使用该函数还是会报函数未定义的错误 需要在window下添加该函数 点击时可以在原型链中找到该函数 设置信息窗体 并为信息窗体里的函数添
  • 福尔摩斯的约会 C语言

    1014 福尔摩斯的约会 20 分 大侦探福尔摩斯接到一张奇怪的字条 我们约会吧 3485djDkxh4hhGE 2984akDfkkkkggEdsb s hgsfdk d Hyscvnm 大侦探很快就明白了 字条上奇怪的乱码实际上就是约会
  • Python之pygame简单介绍

    pygame是Python的第三方库 里面提供了使用Python开发游戏的基础包 但是在进行游戏开发的时候不推荐使用pygame 本文章以示例的形式对pygame的一些简单的使用方式进行讲解 一 游戏最小系统 1 游戏初始化 pygame
  • QT学习——父窗口,信号和槽机制

    一 父窗口 容器窗口 1 概念 创建控件时可以指定停靠在父窗口上 如果没有指定 则飘在外面形成独立的窗体 父窗口本质也是图形控件 常用于表示父窗口类主要包括如下三个 QWidget QDialog 对话框 QMainWindow 主窗口 注
  • android 开屏广告轮播,抖音-TopView(原生开屏)广告投放介绍

    产品简介 用户打开抖音APP时 出现TopView产品形态 原生融入信息流首位 用户体验更沉浸 原生信息流首位广告 避免竞品上下文干扰 品牌安全度高 品牌记忆度高 产品支持播放10s 60s时长的视频 展现位置 规则 1 位置 用户打开抖音
  • Tycho - 用Maven Build Eclipse插件

    为什么80 的码农都做不了架构师 gt gt gt Tycho是一个Maven插件 旨在简化使用Maven构建Eclipse插件 OSGI Bundle等项目 一 插件项目的构建 有了Tycho 构建一个Eclipse插件工程变的非常简单
  • React Native拖拽删除Demo(触摸事件)

    最近学习了下ReactNative中的触摸事件 写个例子实践一下 Demo效果 当触摸红球时开始触发事件 红球随着手指移动改变位置 松开时回到原位 如果拖入蓝色区域则删除 隐藏 单击左上方按钮红球显示在原位置 主要是利用了View触摸函数o
  • Axure RP 9Mac入门知识-基础功能介绍(一)

    Axure RP 9是一款备受瞩目的产品原型设计软件 它可以让你在上面任意构建草图 框线图 流程图以及产品模型 还能够注释一些重要地方 axure rp可支持同时多人写作设计和版本管理控制 这款交互式原型设计工具可以帮助设计者制作出高效率高
  • idea 运行日志查看

    help gt Show Log in Explorer 打开后的文件夹 如果有一些运行错误提示导入至中查看的可以在这里找到 比如在idea执行maven的reimport入时报错 打开后会有对应的记录 日志是按时间顺序追加的 可以直接最下
  • STM32发送AT并用LED显示

    STM32发送AT并用LED显示 1 利用USART1发送数据给使用AT的模块 void SendChar char buff unsigned char i 0 while buff i 0 while USART GetFlagStat
  • Android使用TabLayout+Viewpager+ Fragment实现了底部导航栏的效果

    首先TabLayout一般都是配合Viewpager使用的 Viewpager里的Fragment随着顶部的Tab一起联动 这种场景再熟悉不过了 效果如图所示 一 配置build gradle 添加如下代码 二 values属性文件 1 a
  • 解决华为手机无法使用Android StudioUSB调试功能

    亲测真实有效 废话不多说 跟大多数博客一样 本人照着真机调试步骤一步步来 但是Android Studio始终无法检测到手机 一度怀疑是数据线的问题 然而更换数据线之后问题依旧 折磨了好久 因为本人是华为手机 几经周折 发现是端口被占 最后
  • 机器学习笔记(1)—监督学习和无监督学习

    Day1 写在前面 此系列博客是看的是2022年的吴恩达的机器学习 以下是相关的笔记 如有不对的地方 请大家指出 监督学习 回归算法 分类算法 无监督学习 聚类算法 课后问题 总结 写在前面 始于2022年11月4日 本人双非硕士研一在读
  • 用Ehcache查询性能提升了100倍

    文章来源 石杉的架构笔记原创文章 目录 业务场景 如何通过缓存优化查询接口 基于大数据离线平台进行缓存预热 本地缓存框架 Ehcache 今天给大家来分享一个知识 那就是平时我们开发系统的时候 如何运用 Ehcache 这款本地缓存框架 把
  • matlab 点云精配准(2)——point to plane ICP(点到面的ICP)

    目录 一 算法原理 1 原理概述 2 参考文献 二 代码实现 三 结果展示 1 初始位置 2 配准结果 四 参考链接 五 测试数据 本文由CSDN点云侠原创 matlab 点云精配准 2 point to plane ICP 点到面的ICP
  • openwrt笔记3_自启动+golang

    Openwrt设置开机启动 设置开机启动原理 etc init d目录下面就是系统加载的开机配置 每个配置可以设置START优先级 数字越大启动越靠后 如果有很多需要依赖网络或者USB之类的启动程序最好设置靠后一些 等其他程序启动了再启动
  • 5G/NR PDCCH总结

    1 CCE PDCCH主要用于传输下行控制信息和UL Grant 以便UE正确接收PDSCH及为PUSCH分配上行资源 其分配单位为CCE 1 CCE 6 REG 72 RE 1 REG 1 OFDM symbol 12 subcarrie
  • 开发文档怎么写

    项目开发过程中为了增加程序的可读性和程序的健壮性 方便后期程序的调试和维护 所以需要在开发过程中统一技术规范 一般会在项目初期确定好相关文档作为这一统一的规范 不同公司会对文档做不同要求 划不同的分类 但一般来说 或者拿自己的经验说 大致可
  • -128----127缓存,在栈中获取

    span style font size 13px package test span br style font size 13px br style font size 13px br style font size 13px span