Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Referencing an outer class from an inner class instance

 
Michael Labuschagne
Ranch Hand
Posts: 56
Java Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having trouble understanding why it is exactly that I can't have a reference (this) to my outer class. Obviously because (this) now refers to the inner class, but is there a way around it?



Would I have to do something like this:



Surely there's a more logical way of referring to an outer class from an inner class instance??
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it's OuterClass.this .

Casting the inner class "this" to the outer class will fail; they are not the same class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic