I have an assignment where I am recursively modifiying a matrix of a custom type. Before the recursion, I am trying to make a copy of the matrix ("deep" copy with all attributes/variables of custom type). When the recursion returns however, the original matrix has been modified as if it was passed to the method recursively (and not the copy)
In the code below, "g" is modified after calling "a" with g2:
Copy functionality:
method a(Square[][]) {
...
g2 = new Square[g.length][];
for(int d = 0; d < g.length; d++) {
g2[d] = Arrays.copyOf(g[d], g[d].length);
}
a(g2);
//Here, g has been modified and not the original set of values
}