title: Comparing 2 enums in java
body: <p>I have some code refactoring at hand and see multiple methods taking different enum objects, comparing those and perform some logic. Most of these methods are kind of identical in nature except some minor tweaks. For example</p>
  <pre><code>  private void method1(EnumType1 current,EnumType1 desired) {
       if (current==desired) {
          //perform some logic
       }
     }
      
    private void method2(EnumType2 current,EnumType2 desired) {
       if (current==desired) {
          //perform some logic
       }
    }
  </code></pre>
  <p>the code snippet within (perform some logic can be replaced using a template pattern since some specific logic is there based on specific enum type). I am wondering if I can have a new method to replace the above 2 methods with the following code</p>
  <pre><code>private void method(Object current,Object desired) {
   if(current==desired) {
     //perform some logic
    }
  }
  </code></pre>
  <p>I want to know if  &quot;==&quot; logic work properly when I use this method for different enum types (in my question, I have given reference to 2 different enum types - Enum1 and Enum2), for example say 5 different type of enums. I tested this logic with 3-4 different enum classes with multiple values in it and found it working fine but wanted to check in this forum as well (while I continue reading more about enums)</p>
  <p>If you need any other details on my question then please let me know.</p>