This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is significance of final AB this$0;

 
gauravkv gupta
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]
 
Alexei Kaigorodov
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.
 
Matthew Brown
Bartender
Posts: 4567
8
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic