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

前端 未结 8 1097
醉酒成梦
醉酒成梦 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();
        }
    }
    

提交回复
热议问题