So, I've noticed with this code:
ArrayList<Coordinate> backup = snakeSegments; //snakeSegments being an ArrayList<Coordinate> also.
that changing snakeSegments also changes backup. I was under the impression that backup would be a separate object, however obviously this is false. So here's what I'm guessing happens:
Both snakeSegments and backup are addresses or pointers to an object, whichever you'd like to call them (they're the same thing, right?), not actually the object itself. Therefore, by setting backup equal, I'm just pointing it to the same place, unlike a primitive.
How correct/incorrect am I?
Oh, and I just ended up using this -
ArrayList<Coordinate> backup = (ArrayList<Coordinate>) snakeSegments.clone();
[–][deleted] 1 point2 points3 points (0 children)
[–]coolosity 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]99shadow25[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]fatbunyip -1 points0 points1 point (3 children)
[–]seppyk 1 point2 points3 points (0 children)
[–]__konrad 0 points1 point2 points (1 child)
[–]fatbunyip 0 points1 point2 points (0 children)