title: Generic deep compare equals
body: <p>Basically i don't want to compare elements, but elements that thy contain. It would be cool if following would work, but it does not.</p>
  
  <pre><code>public boolean equals(Ie&lt;T&gt; that) {
      T This = this.value;
      T That = that.value;
      boolean x = That.compareTo(This) == 0;
      return x;
  }
  </code></pre>
  
  <p>What i have done is :</p>
  
  <pre><code>public boolean equals(Object obj) {
      if (obj == null)
          return false;
  
      String tmp = obj.toString();
      if (this.value instanceof Integer)
          return equalsInt(new Ie&lt;Integer&gt;(Integer.parseInt(tmp)));
      // etc.
  
      return false;
  }
  
  public boolean equalsInt(Ie&lt;Integer&gt; ie) {
      Integer This = this.value.intValue();
      Integer That = ie.value;
      boolean x = That.compareTo(This) == 0;
      return x;
  }
  </code></pre>
  
  <p>This is a obvious brute-force solution. Can it be done without <strong>obj.toString();</strong> + new element?</p>
  
  <h2>Edit:</h2>
  
  <p>Class Ie is defined as:</p>
  
  <pre><code>public static class Ie&lt;T extends Number &amp; Comparable&lt;? super T&gt;&gt;
          extends Number implements Comparable&lt;Ie&lt;T&gt;&gt; {
  </code></pre>
  
  <p>Class has rather simple compare to method:</p>
  
  <pre><code>public int compareTo(Ie&lt;T&gt; that) {
      T This = this.value;
      T That = that.value;
      return (This.compareTo(That) &lt; 0 ? -1 : (This
              .compareTo(That) &gt; 0 ? 1 : 0));
  }
  </code></pre>
  
  <p>I am using the class in Collection addall method, where contains is calling equals.</p>
  
  <p>Erikson solution worked fine:</p>
  
  <pre><code>@Override
  public boolean equals(Object that) {
      if (that == null)
          return false;
      if (this == that)
          return true;
      if (that instanceof Ie&lt;?&gt;) {
          Object ThisValue = this.value;
          Object ThatValue = ((Ie&lt;?&gt;) that).value;
          return ThisValue.equals(ThatValue);
      }
  
      return false;
  }
  </code></pre>