title: Is it OK to use == on enums in Java?
body: <p>Is it OK to use <code>==</code> on enums in Java, or do I need to use <code>.equals()</code>?  In my testing, <code>==</code> always works, but I'm not sure if I'm guaranteed of that.  In particular, there is no <code>.clone()</code> method on an enum, so I don't know if it is possible to get an enum for which <code>.equals()</code> would return a different value than <code>==</code>.</p>
  
  <p>For example, is this OK:</p>
  
  <pre><code>public int round(RoundingMode roundingMode) {
    if(roundingMode == RoundingMode.HALF_UP) {
      //do something
    } else if (roundingMode == RoundingMode.HALF_EVEN) {
      //do something
    }
    //etc
  }
  </code></pre>
  
  <p>Or do I need to write it this way:</p>
  
  <pre><code>public int round(RoundingMode roundingMode) {
    if(roundingMode.equals(RoundingMode.HALF_UP)) {
      //do something
    } else if (roundingMode.equals(RoundingMode.HALF_EVEN)) {
      //do something
    }
    //etc
  }
  </code></pre>