File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes method local inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "method local inner class" Watch "method local inner class" New topic

method local inner class

Asanka Vithanage
Ranch Hand

Joined: Oct 24, 2008
Posts: 59
if we create a method local inner class object
Is it eligible for garbage collection after method completion.?

SCJP 1.5 (94%)
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Yes, until you pass this object reference outside the method.

Ankit Garg

Joined: Aug 03, 2008
Posts: 9452

If you create a Method Local Inner class, it is NOT eligible for garbage collection. If you create an instance of the Method Local Inner class, that will be eligible for GC after the method call returns. But there is a twist here. You cannot declare a method local inner class as return type of a method. So you have to use a base type of the method local inner class as the return type of the method.

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: method local inner class
It's not a secret anymore!