• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

what is significance of final AB this$0;

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
source code:


using the javap tool, i got the following, but i dont understand the purpose of adding these statement by compiler. please explain the usefulness of added code by compiler.
Compiled from "AB.java"

what is significance of final AB this$0;

[Added code tags]
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
means reference to an instance of enclosing class AB. This reference is required to access fields amd methods of AB from within nested class B.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know that an inner class can access member variables and methods in the enclosing object, right? Well, this is how the compiler makes that possible. It passes a reference to the enclosing object into the inner class, via a constructor that it generates.

If you modified your original code to call a method in the enclosing object, you'll find that in the decompiled version the call is prefixed with this this$0 reference.
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!