public ClassA(SharableClass object1, SharableClass object2){
this.object1=object1;
this.object2=object2;
}
然后填充object1和object2并共享。那可能吗?
ABOUTYOU
浏览 125回答 4
4回答
慕森王
如果你在 classA 和 classB 中都声明了私有 object1 和 object2,那么你在一个同时依赖 classA 和 classB 的类中初始化这些变量,可能是 picoContainer。然后您可以在 classA 中填充对象数据并在 classB 中使用该数据。如下所示:public class classC{ private SharableObject object1; private SharableObject object2; public classC(){ //initiliaze objects object1 = new SharableObject(); object2 = new SharableObject(); } private classA aClass = new classA(object1, object2); private classB bClass = new classB(object1, object2);//since they refer same objects you can get data from classB when you change data from classA}