calling a function in a class's “owner” class

前端 未结 8 1143
醉酒成梦
醉酒成梦 2020-12-20 20:35

Following pseudocode sums up my question pretty well I think...

class Owner {
    Bar b = new Bar();

    dostuff(){...}
}    

class Bar {
    Bar() {
              


        
相关标签:
8条回答
  • 2020-12-20 21:17
    class Owner {
    
        Bar b = new Bar(this);
    
        dostuff(){...}
    }    
    
    class Bar {
        Bar(Owner owner) {
           owner.doStuff();
        }
    }
    
    0 讨论(0)
  • 2020-12-20 21:19

    I think the way you have written the code, it is not possible to do. But if you declare Bar as inner class of Owner, you might get a closer solution.

    0 讨论(0)
提交回复
热议问题