title: comparing string with enumeration
body: <p>I am analyzing the following piece of code using a static analysis tool called FindBugs.</p>
  
  <pre><code>if(str.equals(enum.SOMEVALUE)) {// do something};
  </code></pre>
  
  <p>where str is a String and enum is an enumeration. The tool generates the following warning for this code, and states</p>
  
  <blockquote>
    <p>This method calls equals(Object) on two references of different class types with no common subclasses. According to the contract of equals(), objects of different classes should always compare as unequal; therefore, according to the contract defined by java.lang.Object.equals(Object), the result of this comparison will always be false at runtime. </p>
  </blockquote>
  
  <p>if I replace the above line of code with this:</p>
  
  <pre><code>if(str.equals(enum.SOMEVALUE.toString())) {// do something};
  </code></pre>
  
  <p>then the warning disappears.But I am not sure if the warning that the tool generates is really true and whether I am fixing it the right way ? because I've seen such comparisons before and it appears to be working correctly.</p>