I know I can instantiate an object of another class, with an argument in its constructor like below:
public class A{
B myB;
myB = new B(this);
}
public class B{
A instanceThatCreatedMe;
B(A myA){
instanceThatCreatedMe = myA;
}
}
I want to do the same thing, but when B is created in a 2D array. In other words, to create a 2D array of B objects, with (this) as parameter in their constructor Something like this:
public class A{
B[][] myBArr;
myBArr = new B[][](this); //<--- That isn't allowed! Neither is myBArr = new B(this)[][]
}
public class B{
//No change
A instanceThatCreatedMe;
B(A myA){
instanceThatCreatedMe = myA;
}
}
Is there a way to do it without having to go through the whole array and setting the instanceThatCreatedMe in each object?
Thank you everyone!
new B[][]doesn't create anyBinstances, so there's no where to pass theAargument.