惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog

博客园 - uu.Net

修改originate使chan_ss7信令传递原被叫 chan_ss7源码分析 chan_ss7中原被叫号码的传递 oracle循环插入数据用于测试 ORA-12154: TNS: 无法解析指定的连接标识符 使用windows route命令来控制双网卡,双网络访问 box & unbox scribefIre试用手记 mysql长连接和短连接的问题 tomcat入门 Tomcat5部署 logrotate---日志轮转 关于gcc的include问题 Centos 时间同步 How to create a gun c/c++ project modules的管理 asterisk上加载G729 codec MySQL C API的一次调用体验 - uu.Net FTP的主动和被动模式
JVM优化引起的逻辑错误
uu.Net · 2011-08-18 · via 博客园 - uu.Net

public class Test2 {

    public static void main(String[] args) {

       Integer i1 = 100;

        Integer i2 = 100;

        if (i1 == i2 )

        System.out.println("相等!");

        else

        System.out.println("不相等!");

    }

如上代码,你觉得会输出什么呢?

结果是“相等”,哈哈,对象的比较,指向不同的地址,怎么会相等?

如果修改数值为256,奇迹出现了,输出“不相等”

这是因为jvm在自动装箱的过程中进行了优化代码,在自动装箱时对于值从–128到127之间的值,使用一个实例。

这样就造成了逻辑错误哦。防不胜防啊!

可靠一点,还是使用如下的初始化对象方法,这样,结果就一直符合逻辑了。

public class Test2 {

    public static void main(String[] args) {

       Integer i1 = new Integer(100);

        Integer i2 = new Integer(100);

        if (i1 == i2 )

        System.out.println("相等!");

        else

        System.out.println("不相等!");

    }

所以如果进行java开发久了,你就会比较头疼那些看上去完全正常的逻辑,在编译后跑出诡异的结果来,这完全靠你对jvm的经验积累哦!