複数のオブジェクトから同じArrayListをどのように参照できるのでしょうか。以下は実際の例ではなく、説明のみを目的としています。
CarCatalogフィールドのあるクラスがある場合ArrayList:
ArrayList<Car> cars = new ArrayList<>();
次に、とのインスタンスを作成し、それを使用しCarCreatorてフィールドをCarDeleter渡します。cars
CarCreator creator = new CarCreator(this.cars);
そして、パラメータをCarCreatorオブジェクトのフィールドに割り当てます。
class CarCreator {
ArrayList<Car> cars;
public CarCreator(ArrayList cars) {
this.cars = cars;
}
}
Carここで、オブジェクトをに追加するCarCreatorと
this.cars
CarCatalogs現場にも出てくるのでしょうか?