Hmmm... What if you do this:
1 2 3 4
| for (int i = 0; i < 10000; i++) { this.x = this.y = i; point[i] = getLocation(); } |
This would surely create new Point objects, right?
Anyway, there's 2 reasons why I think you shouldn't depend on an optimization like this:
1) Java doesn't optimize this, maybe a specific JVM does.
You don't want to depend too much on VM specific optimizations.
2) It doesn't make any sense to create new Point objects for getting the location of some object everytime you query it. Point has getters and setters anyway.
EDIT: 3) What Orangy Tang said
