• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inner classes  RSS feed

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i have an error when i try to access the non final variable in the overridden method. Can anyone help me out. how are such variables visible. also what would happen if i passed the reference of the object to another method and then invoked the method.
 
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
args is a local variable. once method completed, no more live. but the anonymous inner class object you have created[which have the args] lives after the method completion also. so now problem right? suppose the local variable args declared as final, then compiler takes one copy of the variable[Syntactic sugar] into the inner class.

coming to your problem make args variable as final. for more details search here in coderanch. similar problem discussed many time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!