Following pseudocode sums up my question pretty well I think...
class Owner {
Bar b = new Bar();
dostuff(){...}
}
class Bar {
Bar() {
//I want to call Owner.dostuff() here
}
}
Bar b
is 'owned' (whats the proper word?) by Owner
(it 'has a'). So how would an object of type Bar
call Owner.dostuff()
?
At first I was thinking super();
, but that's for inherited classes. Then I was thinking pass an interface, am I on the right track?
If dostuff is a regular method you need to pass Bar an instance.
Note that there may be many owners to Bar and not any realistic way to find out who they are.
Edit: You might be looking for an Inner class: Sample and comments.
I think you are looking for nested Clases Nested Classes Sun
This way u can write
outer.this.doStuff();
Have a look to that topic: Inner class call outer class method