If dostuff is a regular method you need to pass Bar an instance.
class Owner {
Bar b = new Bar(this);
dostuff(){...}
}
class Bar {
Bar(Owner owner) {
owner.dostuff();
}
}
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.
class Owner {
InnerBar b = new InnerBar();
void dostuff(){...}
void doStuffToInnerBar(){
b.doInnerBarStuf();
}
// InnerBar is like a member in Owner.
class InnerBar { // not containing a method dostuff.
InnerBar() {
// The creating owner object is very much like a
// an owner, or a wrapper around this object.
}
void doInnerBarStuff(){
dostuff(); // method in Owner
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…