複数のオブジェクトから同じ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
現場にも出てくるのでしょうか?