It is probably to do with caching; I think, when you start instantiating Integer objects, the JVM creates a cache of small (-128 <= i < 128) values. When you "box" the 12 into an Integer, the JVM reuses the Integer(12) in the cache. So you have the same Integer(22) twice, so == returns true.
Joined: Feb 22, 2007
Joined: Oct 13, 2005
subject: Doubt in Paramater Passing (Primitives to Wrappers)