I am not able to understand how the Java Constant Pool for Integer works.
I understand the behavior of Strings, and hence able to justify myself that it is the same case with Integer Constants also.
So, for Integers
Integer i1 = 127;
Integer i2 = 127;
System.out.println(i1==i2); // True
&
Integer i1 = new Integer(127);
Integer i2 = new Integer(127);
System.out.println(i1==i2); // False
Till here everything goes in my head.
What I am not able to digest is, it behaves differently when I increase the integer from 127. This behavior changes after 127, below is the code snippet
Integer i1 = 128;
Integer i2 = 128;
System.out.println(i1==i2); // False. WHY?????
Can somebody help me understand this?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…