I have a problem and I just don't know how to solve it.
I want to make a class, where a 2D int array is saved twice. One time as final to stay like it is and one, which I can modify.
In short my class looks like this:
private static class Class {
private final int[][] firstForm;
private int[][] modify;
public Class(int[][] firstForm){
this.firstForm = firstForm;
this.modify = firstForm;
//I also already tried .clone() on both
}
public void setValue(int x, int y, int val){
if(firstForm[x][y]!=0){
System.out.println("ERROR!);
return;
}
modify[x][y]=val;
}
}
Now when I use the function setValue not only the value of modify changes, but also the one of firstForm.
I already tried with this.modify = firstForm.clone();, but the result is the same. Can somebody please help me and tell me what I do wrong?
setValue.