This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
the == checks to see if both references are for the same object.
iThree and iFour are different objects so the result is false. That should be fairly easy to understand (notice the use of "new" when creating the objects).
When an int is boxed into an Integer as is happening when you call "method" then if the int is between -128 and 127 inclusive then the jvm uses a cache. So all boxed references of the same int in that range will refer to the same object.
All the tests will be true if you use .equals() instead of ==.
[ July 29, 2008: Message edited by: Paul Beckett ] [ July 29, 2008: Message edited by: Paul Beckett ]