Originally posted by Kiran Gavate:
Could somebody pls explain in more details? I am not able to get it. Isn't it that when the value is between -128 and 127, the wrapper object will be created in the object pool? Which two objects are eligible for GC?
When you call the "new" operator, A new object will be instantiated. The JVM doesn't know about or use an object pool for this. This object pool that you are referring to, is related to the Integer class... specifically, the valueOf() method checks to see if the resulting Integer is within the -128 and 127 range. And if it is, it will return an object that it had constructed eariler.
This valueOf() method is what is used internally by autoboxing. No autoboxing is used in this example, nor is the valueOf() method used.
Henry
[ February 09, 2007: Message edited by: Henry Wong ]