Unexpected result when comparing ints
Posted
by
Raghav
on Stack Overflow
See other posts from Stack Overflow
or by Raghav
Published on 2012-08-30T21:07:48Z
Indexed on
2012/08/30
21:38 UTC
Read the original article
Hit count: 230
java
I tried to compare two ints with the following cases and got unexpected results
when I did the following, @@@ was printed.
class C { static Integer a = 127; static Integer b = 127; public static void main(String args[]){ if(a==b){ System.out.println("@@@"); } } }
when I did the following, @@@ was not printed.
class C { static Integer a = 145; static Integer b = 145; public static void main(String args[]){ if(a==b){ System.out.println("@@@"); } } }
Can anyone tell me what could be the reason.
© Stack Overflow or respective owner