title: Java factory method caching
body: <p>I have to develop something like a game of life. For that, I have a class called <code>CellPosition</code> that has <code>x</code> and <code>y</code> fields. In order to efficiently use memory, I would like to use some kind of factory method.</p>
  
  <p><code>CellPosition.at(int x, int y)</code> which would return an instance of <code>CellPosition</code>. I would like though to cache the objects that have the same <code>x, y</code> pair. I though of a <code>List</code> or a <code>HashMap</code>, but I cannot figure out what to use as a key. A concatenation of <code>x</code> and <code>y</code> in a string is doubtingly a good idea. </p>
  
  <p>On the other hand, is it a good idea to just create an object each time and just redefine the <code>equals()</code> method to compare the objects and throw away any caching?</p>