Answer the question
In order to leave comments, you need to log in
int and integer
I am one such fool that I did not know that the following code produces false:
Integer i = 200;
Integer j = 200;
if(i == j){
System.out.print("true");
}else{
System.out.print("false");
}
Integer i = 100;
Integer j = 100;
if(i == j){
System.out.print("true");
}else{
System.out.print("false");
}
Answer the question
In order to leave comments, you need to log in
As far as I know, values from -128 to 127 are in the machine's java object pool, so they have one address in memory, and you compare objects using ==, i.e. link
And here it is - the same cache:
www.grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/Integer.java#573
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question