0

Why is the second one false?

Code: Integer i1 = 127; Integer i2 = 127; System.out.println(i1==i2); //true i1 = 128; i2 = 128; System.out.println(i1==i2); //false? Please explain

28th Dec 2018, 4:44 PM
Asirap
4 odpowiedzi
28th Dec 2018, 4:55 PM
InvBoy [ :: FEDE :: ]
InvBoy [ :: FEDE :: ] - avatar
0
InvBoy in your code you wrote of int instead of Integer. Correcting that and running the code will show the second one is false.
28th Dec 2018, 5:57 PM
Asirap
0
Gordie thank you for your answer. i do not understand the part about caching and how it makes i1 and i2 unequal. Can you please explain?
28th Dec 2018, 5:59 PM
Asirap
0
Gordie thanks you so much! your explanation was very clear and helpful.
28th Dec 2018, 6:18 PM
Asirap