File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method-local inner class object cannot use the local variables

 
bob jacosin
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
method-local inner class object cannot use the local variables
of the method the inner class is in. Why not?
 
Moojid Hamid
Ranch Hand
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The initiated objects of the class can live past the life of method invocation, once the method returns and the stack unwinds the local variables are gone, but the object is still alive. Local classes can however use final local variables.
 
bob jacosin
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible to use the method-local inner class as return type of the method where the inner class is in?
 
Moojid Hamid
Ranch Hand
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bob jacosin wrote:is it possible to use the method-local inner class as return type of the method where the inner class is in?


No but you can return the super type, or pass it as a parameter to a method that accepts its supper type or assign it to a instance variable ( of a type that is super class of your local class). If there is any outside reference to the local class object after the method finishes it will still be accessible.
 
bob jacosin
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh ok...thats it i see thank you...
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bob jacosin wrote:ahh ok...thats it i see thank you...
If by "I see" you mean "I don't understand", please say so and ask for more explanation.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic