class - Java stream misconceptions… some clarification? -


this question has answer here:

i have written following code in java,

integer i=10; integer i1=10; s.o.pln(i==i1);//true integer j=100; integer j1=100; s.o.pln(j==j1);//true integer k=1000; integer k1=1000; s.o.pln(k==k1);//false 

here, integer wrapper class, must show true declared types. showing false 1000.

can explain reason behind it.

first, note when applied objects (like integer), == operator compares references.

next, note these assignments imply boxing conversions (also called 'autoboxing') type int (primitive) integer (object).

and according java specification - conversions

"if value being boxed ... int or short number between -128 , 127, let r1 , r2 results of 2 boxing conversions of p. case r1 == r2."


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -