Wrapper objects and equality
<p>Why is it the case that if I run the .equals method on two wrapper objects it will return true as per the WrapperEqualsEquals Class below <strong>but</strong> (and I stress the but) why do we need to override the equals method in the Blob Class below in order for it to return true. Basically why do the wrapper objects get away with having to do an override of the .equals method?</p>

<pre><code>    class WrapperEqualsEquals
    {
       public static void main(String []args)
       {
         Integer one=new Integer(1);
         Integer oneB=new Integer(1);

         System.out.println(one == oneB);
         System.out.println(one.equals(oneB));

       }    
</code></pre>

<h1>        }</h1>

<pre><code>    class OverrideEquals
    {
      public static void main (String [] args)
      {
        Blob a= new Blob(1,"a");
        Blob b= new Blob(1,"a");



        System.out.println(a==b);
        System.out.println(a.equals(b));

       }
</code></pre>

<h1>         }</h1>

<pre><code>    class Blob
    {
      int blobNumber;
      String blobText;

      Blob(int blobNumber,String blobText)
      {
       this.blobNumber=blobNumber;
       this.blobText=blobText;
      }

          //"overriding" the 'equals' method

          public boolean equals (Object o)
      {

            if (o instanceof Blob)
    {
        Blob o2=(Blob)o;
        return ((o2.blobNumber==this.blobNumber) &amp;&amp;(o2.blobText==this.blobText))?
                    true:false;
    }

            else
    {
        return false;
    }
}
</code></pre>

<p>}</p>
