关于Integer的"=="

当你运行Integer i =1时,发生了什么? 引言:今天上班时,有个同事在群里问了一句 public static void main(String[] args) { Integer a = 1; Integer b = a; b = 2; System.out.println(a); } 这个输出什么。以我对于我们猿的尿性的熟知程度,当机立断告诉他 “1”, 阅读详情
public static void main(String []args) {
		Integer a = 1;
		Integer b = 1;
		Integer c = 200;
		Integer d = 200;
		System.out.println(a == b);
		System.out.println(c == d);
	}


输出结果:

true

false

使用1或者1000赋值给Integer时,Java会翻译为Integer.valueof(xxx),附上源码,在-128到127之间的时候直接return IntegerCache.cahe[]了,因此出现了这个结果

    private static class IntegerCache {
        static final int high;
        static final Integer cache[];

        static {
            final int low = -128;

            // high value may be configured by property
            int h = 127;
            if (integerCacheHighPropValue != null) {
                // Use Long.decode here to avoid invoking methods that
                // require Integer's autoboxing cache to be initialized
                int i = Long.decode(integerCacheHighPropValue).intValue();
                i = Math.max(i, 127);
                // Maximum array size is Integer.MAX_VALUE
                h = Math.min(i, Integer.MAX_VALUE - -low);
            }
            high = h;

            cache = new Integer[(high - low) + 1];
            int j = low;
            for(int k = 0; k < cache.length; k++)
                cache[k] = new Integer(j++);
        }

        private IntegerCache() {}
    }

    /**
     * Returns a <tt>Integer</tt> instance representing the specified
     * <tt>int</tt> value.
     * If a new <tt>Integer</tt> 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.
     *
     * @param  i an <code>int</code> value.
     * @return a <tt>Integer</tt> instance representing <tt>i</tt>.
     * @since  1.5
     */
    public static Integer valueOf(int i) {
        if(i >= -128 && i <= IntegerCache.high)
            return IntegerCache.cache[i + 128];
        else
            return new Integer(i);
    }


开源CMDB与资产管理平台对比报告 本文对比分析了9款主流开源CMDB平台,从集成能力、功能完整性和多语言支持三个维度进行评测。重点介绍了VeCMDB、蓝鲸CMDB、WeCMDB和OpsAny等国产平台的特色:VeCMDB以动态模型和自动发现见长;蓝鲸CMDB适合超大规模企业级应用;WeCMDB专注金融级高并发场景;OpsAny提供一体化运维解决方案。针对不同规模企业给出选型建议:中小团队推荐Snipe-IT等轻量工具;大型企业建议蓝鲸或WeCMDB;需国产化适配的可选VeCMDB或OpsAny。文章还特别指出iTop、GLPI等适合ITIL 阅读详情

相关推荐

从安装到跑通第一个例程:Halcon 20.11深度学习版环境搭建全记录

本文详细记录了Halcon 20.11深度学习版环境搭建的全过程,从安装配置到运行第一个例程,特别针对CUDA版本冲突、算子验证和样本数据预处理等常见问题提供解决方案。通过实战案例展示PCB缺陷分类流程,帮助工程师快速掌握工业级图像处理技术,提升深度学习模型在工业质检中的应用效率。

weixin_28739079的博客 223

Integer==陷阱

Part 1.创建Integer //话不多说,Integer==1;与Integer j=1000;源码执行如下 public static Integer valueOf(int i) { if (i >= IntegerCache.low && i <= IntegerCache.high) return IntegerCache.cache[i

qq_25622107的博客 675

速腾16线激光雷达(RS-16)在ubuntu18.04系统下跑SC-A-LOAM算法

说明: 简要记录一下速腾16线激光雷达即RS-16在ubuntu18.04系统下跑SC-A-LOAM算法的过程,因为SC-A-LOAM算法源码不支持RS雷达的数据,大致思想就是先将rs雷达发布的激光数据转换为velodyne类型的数据,考虑到接下来还要基于RS-16实时运行SC-A-LOAM算法,这里提前将RS_SDK驱动安装好。 1 搭建SC-A-LOAM算法运行环境 首先需要在电脑上搭建SC-A-LOAM算法的运行环境,见文章《ubuntu18.04搭建SC-A-LOAM环境并运行》 本文所使用的系统架

超爱吃小蛋糕的66的博客 2373

使用==比较的一个误区(如Integer)

使用Integer对象时,使用它==来比较值是很诱人的,因为这是您将使用的int值。在某些情况下,这似乎有效: Integer int1_1 = Integer.valueOf("1"); Integer int1_2 = Integer.valueOf(1); System.out.println("int1_1 == int1_2: " + (int1_1 == int1_2))

linxijun的博客 4149

莫兰指数stata命令_一文读懂16个sp系列stata空间计量命令及应用

spcompress:Compress Stata-format shapefile压缩数据成stata格式的shapefile2、Looking at data/观测数据2、Looking at data/观测数据grmap:Graph choropleth maps绘制等值区域图spdistance:Calculator for distance between places计算区域之间距离3...

weixin_39719989的博客 822

手把手教你学Simulink--基于微电网的建模与仿真场景实例:独立运行模式下微电网的能量管理系统设计

本文详细介绍了使用Simulink对独立运行微电网能量管理系统进行建模与仿真的完整流程。主要包括:系统结构设计(分布式能源、储能系统、负荷等模块)、建模步骤(从创建项目到实现能量管理策略)、仿真设置与结果分析。通过建立基于规则的控制逻辑和优化调度算法,实现微电网的自主运行和能量优化管理。文章还提供了参数优化和多目标改进建议,为新能源和智能电网领域的研究与应用提供了实用指导。

MHD0815的博客 8589

Integer类型的数据比较值是否相等用==结果不对

结果:Integer类型本该相等的值用==比较不出相等来,那么就用equals,后来我改成了province.equals(provinCode)就得到我想要的结果了 过程 如图所示,provinceCityDtos是我从数据库里边查询出来的list数据,然后我进行了一个for循环遍历,从第一行记录里边拿到Integer类型的provinceCode的值时能比较我的provinces值相等,因为我的 provinceResult(最外层的for循环)是从provinceCityDtos拿的,所以肯..

dsl 976

OCR文字识别基础

ocr文字识别

m0_47405013的博客 1755

int和Integer的区别

我们大家都知道int和Integer的区别是:int默认值为0,Integer默认值是null,Integer是int的包装类,Integer有很多的方法可以使用!但是还有很多区别,例:                 int i1=1;  Integer i2=1; Integer i3=new Integer(1);                 //Integer会自动拆箱为i

hengliang_的博客 670

【K210+STM32项目】基于K210与STM32协同工作的智能垃圾分类系统设计与实现(更新3.0版本)(完整工程资料源码)

STM32F407STM32F407_2(含有app功能)

嵌入式技术开发 2498

SAP S/4HANA 数据 API 化与 MCP 集成全流程实战指南

通过 RAP 发布 OData、利用 Communication Arrangement 打通外网、再在 MCP-server 里封装函数签名,你就能把 S/4HANA 的核心数据安全、标准化地暴露给任意支持 MCP 的大模型。这条链路的每一个环节都由 SAP 与 MCP 社区提供了现成框架,既兼顾了企业合规,也让 LLM 落地更为轻量。期待你在项目里把这些拼图真正串联起来,让业务数据与生成式 AI 碰撞出高价值的火花。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 982

Integer的"=="问题

Integer 的“ == ”问题 public class IntegerQuestion { public static void main(String[] args) { Integer f1 = -129, f2 = -129, f3 = -128, f4 = -128; Integer f5 = 127, f...

weixin_30512089的博客 80

ValueError:Using a `device_map`, `tp_plan`, `torch.device` context manager or setting `torch.set解决方案

本文主要介绍了ValueError:Using a `device_map`, `tp_plan`, `torch.device` context manager or setting 'torch.set_default_device(device)` requires `accelerate`解决方案,希望能对使用transformers的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 3万+

包装类Integer判断“==”相等

Java integer类的比较

qq_51788416的博客 290

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Integer“==”和Integer“equals”

以前有碰到Integer“==”和Integer“equals”的问题,但是都没有总结,有时开发时也忘记注意了   最近有碰到这个问题了,发现是一个容易忽略的注意点,所以稍微整理了一下   看下面这段代码:   Java代码   /**   * @author wuliwei   *   */   public class IntegerEqu...

mno2330的博客 261

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Integer的“==”

Integer的“==” 使用Integer时,我们可能会遇到以下令人困惑的现象` public static void main(String[] args) { Integer a=11; Integer b=11; if(a==b) System.out.println("true"); else System.out.println("false"); } 输出...

weixin_43751710的博客 417

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Integer的"=="比较

Integer的"=="比较 package me.zhao; public class IntegerTest { public static void main(String[] args) { int a1 = 127; int a2 = 127; int b1 = 128; int b2 = 128; System.out.println(...

赵丙双的博客 607

关于Integer的一些"=="比较

 首先看第一道题:  Integer a = 128;  Integer b = 128;  System.out.println(a==b);这道题答案是什么呢?  再来看第二道题:  Integer a = 127;  Integer b = 127;  System.out.println(a==b);看上去差不多吧,那这道题答案又是什么呢? 答案:1.f

cqf7174的专栏 647

Integer包装类比较时“==”和equals()的区别及原因

Integer包装类,比较时“==”和equals()区别、原因

qq_33556244的博客 674

Integer的“==”返回值

  /** * Created by spring on 10/26/13. */ public class Test { public static void main(String args[]){ Integer i_128 = -128; Integer j_128 = -128; System.out....

aliahhqcheng的专栏 403

Integer的“==”分析

先来看一段代码: public class Demo1{    public static voidmain(String[] args){        Integer x = 127;        Integer y = 127;        Integer j = 128;        Integer k = 128;        System.out.println(

caibaoH的博客 700

Integer类型用 “==” 比较的问题

面试题目,Integer类型判断 == 的问题

Eric的博客 4806

Integer 中的 “==” 陷阱

先看一段代码: static boolean test(Integer a, Integer b) { return a == b; } public static void main(String[] args) { Sy...

chuangong2592的博客 337

Java Integer之“==”问题

有趣的一个Java基础类的问题。Integer a = 100; Integer b = 100; System.out.println(a == b); Integer c = 1000; Integer d = 1000; System.out.println(c == d);输出分别为true,false. “==”我们都知道是引用目标地址的判断是否相等。因此上述应该都是false才对的。但

zhuxiaoyu1999 809

Integer使用 “==“ 比较大小

类似Integer这样的包装类,在使用 "==" 比较大小的时候,会调用valueOf方法进行比较。 下面是源码 public static Integer valueOf(int i) { if(i &gt;= -128 &amp;&amp; i &lt;= IntegerCache.high) return IntegerCache...

向来缘浅,奈何情深 4204
上一篇: 电信设备进网管理
Android_Robot
博客等级 码龄15年 62粉丝 88原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值