• Post Reply Bookmark Topic Watch Topic
  • New Topic

reference to enclosing instance  RSS feed

 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This code fails, as this refers to the Head. How do I refer to the Dingbat to whom the head belongs? I could send a reference of the Dingbat to the Head constructer, but this seems like it ought to be unnessecary. Is there a more graceful way?
 
Rovas Kram
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Head doesn't belong to Dingbat in an objected orient sense. The way you coded it, Head is only accessable from Dingbat. You could create a Head without a Dingbat in main, for example.
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Head is not static. It is intrinsically tied to a dingbat
 
Rovas Kram
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please regard my previous post. I was tempted to remove it but I think I should just admit I was wrong. This is an interesting question...I'm working on a response...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To refer to the enclosing instance, you use the name of the enclosing class plus the keyword "this" --- i.e., in the given example, use "Dingbat.this".
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The comparison you use will always fail, as the this keyword refers to a Head object and ding refers to a Dingbat object. You can look at the enclosing instance for an inner class by using a qualified this keyword, which is nothing more than this prefixed by the name of the class. So in you case it will be:



Hope that helps,
E
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank ye
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!