title: The equals() method in Java works unexpectedly on Long data type
body: <p>Let's first consider the following expressions in Java.</p>
  
  <pre><code>Integer temp = new Integer(1);
  System.out.println(temp.equals(1));
  
  if(temp.equals(1))
  {
       System.out.println("The if block executed.");
  }
  </code></pre>
  
  <p>These all statements work just fine. There is no question about it. The expression <code>temp.equals(1)</code> is evaluated to <code>true</code> as expected and the only statement within the <code>if</code> block is executed consequently.</p>
  
  <hr>
  
  <p>Now, when I change the data type from <code>Integer</code> to <code>Long</code>, the statement <code>temp1.equals(1)</code> is unexpectedly evaluated to <code>false</code> as follows.</p>
  
  <pre><code>Long temp1 = new Long(1);
  System.out.println(temp1.equals(1));
  
  if(temp1.equals(1))
  {
      System.out.println("The if block executed.");
  }
  </code></pre>
  
  <p>These are the equivalent statements to those mentioned in the preceding snippet just the data type has been changed and they behave exactly opposite. </p>
  
  <p>The expression <code>temp1.equals(1)</code> is evaluated to <code>false</code> and consequently, the only statement within the <code>if</code> block is not executed which the reverse of the preceding statements. How?</p>