Search code examples
javapoint

java.awt.Point translate un-doing itself


I have the following code with start and end each of the type java.awt.Point.

start.translate(-1, 0);
end.translate(1, 0);

However, when I run this code with start = (0, 0) end = (0, 0), both start and end turn out as (0, 0). Why is this happening, and is it only me?

EDIT Even more strangely, when I look at the coordinates before line 2 and after line 1, both points start and end are at (-1, 0); essentially, translate(int x, int y) translated both points!


Solution

  • The only way this could happen is that the start and end variable point to the exact same object. And so, after the point (0,0) is translated by -1 in the x-coordinate, and then again by +1, you get (0,0) again. Check the code which creates the start and end objects.