• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing inner class -- error?

 
Steve Edwards
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What seems to be an error in "Getting in Touch with your Inner Class" (Campfire Stories): You can also instantiate both the outer class and inner class at the same time:


Recreating the whole example in Eclipse, it doesn't pass the syntax checker. According to JCHQ, the syntax is

This compiles and runs for me. Excuse an uppity beginner, but what do you think?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the article, in the code just above the statement you pointed out, they have the variable with the correct type Outer.Inner. So you are correct. Probably a typo.

Thanks, I'll try to get someone to fix it.
[ January 25, 2005: Message edited by: Barry Gaunt ]
 
Steve Edwards
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry,

Thanks, you answered my question. Yes, I see the line you are talking about where Outer o is instantiated first, and then Outer.Inner i from there. The typo's a little more unfortunate since it comes right after the comment:

// Inner i = new Inner();
// NO! Can't instantiate Inner by itself!

I hope my picking comes across in good humor. Actually, the article is the most helpful explanation I've come across and helped a lot. Thank you!

Steve
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another possiblity is that there is an import statement at the top of the source. Something like:

If so, this will make it possible to use the syntax as given:


Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic