title: Why does this String.equals() method always return false?
body: <p>I have a class for which I have implemented a custom hashCode() and equals(Object) method using the Eclipse method generator. Each object of the class has a String field called <code>mUid</code> which should be unique and is enough to determine equality. The overridden methods look like this:</p>
  
  <pre><code>    @Override
  public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result + ((mUid == null) ? 0 : mUid.hashCode());
      return result;
  }
  
  @Override
  public boolean equals(Object obj) {
      if (this == obj)
          return true;
      if (obj == null)
          return false;
      if (getClass() != obj.getClass())
          return false;
      DataSource other = (DataSource) obj;
      if (mUid == null) {
          if (other.mUid != null)
              return false;
      } else if (!mUid.equals(other.mUid))
          return false;
      return true;
  }
  </code></pre>
  
  <p>But for some reason, when I compare two objects of my class, it always returns false. I've stepped through the code with a debugger and can determine that the mUid strings are the same. But my <code>equals(Object)</code> method always returns false at the line </p>
  
  <p><code>if (!mUid.equals(other.mUid)) {return false;}</code>. </p>
  
  <p>This means the String equals() method is saying the strings are not equal. But, in the debugger I can see that even their hashcodes are equal.</p>
  
  <p>Here is a debugging screenshot:
  <img src="https://i.stack.imgur.com/t0TU5.png" alt="Debugging screenshot">
  Can anyone please explain what is happening?
  Thanks.</p>
  
  <h2>Update: It works!</h2>
  
  <p>I should point out that I am not calling the equals(...) method directly, but rather from <code>List&lt;DataSource&gt; list.contains(DataSource)</code>. It turns out that if I step through the <code>equals(Object)</code> code, it shows me that it returns false for comparing every object in the list (even if there is a match). But it seems the <code>List.contains()</code> method returns the right value (true or false) anyway. Don't know why this is, but it works. I had an extra semicolon after the <code>if(list.contains(dataSource));</code> so I could not rightly see that <code>contains()</code> was working fine. <strong>Thanks for your help everyone</strong>.</p>