This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Here's an obscure Java question that I hope one of you can answer: At the top level, I have defined a subclass of an inner class. From a method in that subclass, is there any way to refer to the outer class object or to the outer class object's variables and methods? In the code below, the method dostuff() is written identically in Inner and SonOfInner. It shows a variety of ways to access methods and data in the outer class -- but all of them fail for the SonOfInner class. Is there any way to do this at all? -----------------------------------
Afaik, there isn't. I think you do have a serious design problem here. Why does SonOfInner need to access Outer.this? Do you have a real world example where you need to do this?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Jun 06, 2002
This is not a real-world example. I am just starting to learn Java, and noticed that it is possible to declare, at the outer level, a subclass of an inner class. I'm trying to understand how things work, and doubt that I would ever do this in "real life".