• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please Clarify Code( "final MainWindow this$0;" and "this$0 = MainWindow.this; super();")  RSS feed

 
Abdulazeez Hassan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going through this code and kind of need help to understand a part of it.



What effect does this statement have on the program especially "final MainWindow this$0;" and "this$0 = MainWindow.this; super();". From What I understand super() should be the first statement of the class. So I think it is useless to have such code in a program. Kindly help me clarify this.

 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you decompile this code? Because the this$0 is a reference to the instance of the enclosing class, and usually it's implicitly added by the compiler. I've never seen anyone add it manually.
Another giveaway about you (or someone else) having decompiled it is the assignment to this field before the call to super(); that's not allowed, and won't compile again.
 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every non-static inner class instance, even that of an anonymous one, has a reference to an outer class instance, in context of which it is instantiated. Compiler provides it without us needing to make it explicit in code. When we decompile the code, some of this compiler "magic" also gets decompiled and printed in the output.

You can safely delete the lines 8 and 12 in your code below:

 
Abdulazeez Hassan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the clarification. I understand it perfectly now. Rob thanks for the answer, I didn't decompile the code it is an assignment given to me to read trough. May be my tutor did. Thanks anyway.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch

I have edited your post because the long lines make it difficult to read. It is a good idea to restrict line length to 120 cahracters. That way nobody has to scroll right and left.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!