• Post Reply Bookmark Topic Watch Topic
  • New Topic

why this output ?  RSS feed

 
Chirag Vithlani
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.*;



class test1 {
public static void main(String[] args) {
test1 inst_test = new test1();
int i1 = 2000;
int i2 = 2000;
inst_test.method( i1 , i2 );

}
public void method( Integer i , Integer eye ) {
System.out.println(i == eye );
}
}

output:
false
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has to do with two java concepts.
First, autoboxing (the automatic conversion between primitives and wrapper classes) and
secondly, the difference between the == operator and the equals method.

This topic was mentionned just yesterday

Bart
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you expect it to be true?
 
Guru dhaasan
Ranch Hand
Posts: 126
Java Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but do the int is having more than 2000 right ........ i guess upto 32,656
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!