I am curious as to how Java would handle a situation as follows, I will provides some insight into what it is that I am doing.
I am busy writing a Sudoku Solver for a ProjectEuler problem, I am using a 2D Array of Nodes (Custom Object):
Node[][] grid;
The Following is my Node Class:
public class Node {
public int x;
public int y;
public int value;
public int quadrant;
public ArrayList<Integer> possibleNumbers;
public SudokuNode() {}
public SudokuNode(int x, int y, int value, int quadrant) {
this.x = x;
this.y = y;
this.value = value;
this.quadrant = quadrant;
this.possibleNumbers = new ArrayList<Integer>();
}
public ArrayList<Integer> getArray() {
return possibleNumbers;
}
}
Now at some stage during the process of Solving the Puzzle I might find that I need to take a guess of sorts, what I would like to do is backup the current state of the grid into another object called Guess, that structure follows as well:
public class Guess {
public Node[][] grid;
public int x;
public int y;
public Guess(Node[][] puzzle, int x, int y) {
this.grid = puzzle;
this.x = x;
this.y = y;
}
}
In this object I wish to make a copy of the Current Grid, aswell as the X and Y coordinates of the Node where I took a guess.
What I am curious about is whether or not Java will make a complete copy of the grid, or merely use a pointer to the original one?
A friend of mine is writing a Solver in Javascript, I am aware they are completely different Languages, he ran into a problem where the grid wasn't being backed up as it was still referencing the Original grid he had created and so couldn't revert to the previous state in the event that the guess turned out to be wrong.
I would just like to understand what happens when I say do something like this:
Node[][] backup = currentGrid;
Does it make an entirely new copy or not?
Sorry if this is a duplicate or silly question to ask. I am teaching myself programming and therefore I might have missed something or just don't understand some core concepts.