title: Checking objects for identity and Sonar issues
body: <p>We are checking the quality of our code using Sonar, and Sonar found code which compares objects for identity like this:</p>
  
  <pre><code>if (cellOfInterest == currentCell) { … }
  </code></pre>
  
  <p>Sonar finds this kind of identity check peculiar enough to call it critical and proposes to replace the identity check (using <code>==</code>) with a check for equality (using <code>.equals()</code> instead).  Identity checks, so the rationale behind this, are often not what is meant.</p>
  
  <p>In our case, however, we iterate through a list of <code>Cell</code>s and check in each iteration (<code>currentCell</code>) whether we are handling a special cell we already have (<code>cellOfInterest</code>).</p>
  
  <p>I'd like to hear if there are other patterns than ours which are common and which avoid this issue simply by using a different design.  Or what solutions do you propose to avoid using an identity check in the mentioned situation?</p>
  
  <p>We considered a replacement of the identity check with an equality check as described above but it does not seem applicable in our situation because other cells might be "equal" as well but not identical.</p>
  
  <p>All ideas are welcome!</p>