"But even after the method completes, the inner class object created within it might still be alive on the heap if, for example, a reference to it was passed into some other code and then stored in an instance variable."
How would you reference the method-local inner class outside of the method? For example, how would I declare an instance variable in the class MethodLocalTest to store the instance of MethodLocal class instantiated as below (this is off the top of my head so please ignore any silly mistakes)?
I can't find anyway of doing this (for example, MethodLocalTest.MethodLocal) and a quick look on the web suggests that the statement in S&B may not be correct. Does anyone know for sure (else I'll have a look in the langauge spec).
Yeah suposed I get the point (I realised after posting that by upcasting you could return a reference to the instance and therefore it would continue to live on the heap) but wouldn't this be kind of pointless as you couldn't do much useful with it? [ October 20, 2008: Message edited by: Graeme Jenkinson ]