KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
EDIT: OK, OK, I misread. I'm not comparing an int to an Integer. Duly noted. My SCJP book says: When == is used to compare a primitive to a wrapper, the wrapper will be unwrapped and the comparison will be primitive to primitive. So you'd think this code would print true : Integer i1 = 1; //if this were int it'd be correct and behave as the book says. Integer i2 = new Integer(1); System.out.println(i1 == i2); but it prints false . Also, according to my book, this should print true : Integer i1 = 1000; //it does print `true` with i1 = 1000, but not i1 = 1, and one of the answers explained why. Integer i2 = 1000; System.out.println(i1 != i2); Nope. It's false . What gives?
Tags (comma-separated)
Save Edits
Cancel