This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes what is significance of final AB this$0; Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "what is significance of final AB this$0;" Watch "what is significance of final AB this$0;" New topic
Author

what is significance of final AB this$0;

gauravkv gupta
Greenhorn

Joined: Feb 18, 2012
Posts: 21
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

Joined: Feb 24, 2008
Posts: 17
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

Joined: Apr 06, 2010
Posts: 4344
    
    8

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: what is significance of final AB this$0;
 
Similar Threads
Scjp Exam questions. Please help
the "this" factor
String addition
instanceof comparing two different branches of the inheritance tree