Aakash Goel wrote:
What is the logic behind this?
I am completely unaware of the logic used here. Can somebody explain?
The "cache" being referred to here, is the cached in the Short class -- basically, the class will pre-instantiate a certain number of Short objects in a range... Later, when the valueOf() method is called, and the value is within the range, it will return the object from the cache, instead of creating a new one. And since autoboxing uses the valueOf() method, it uses the cache.
In relation to this question, the short is within the range, hence, it can't be GCed, because the object returned is still in the cache. In the errata, the short value is changed so that it is not in the cache.
Henry