title: Writing contains() for a generic collection
body: <p>I'm writing a skiplist class in java as an excercise. I've written a class called <code>SkipListInternal&lt;E&gt;</code> which contains the actual skiplist. I've also made a wrapper class called <code>SkipListSet&lt;E&gt;</code> which implement the <code>SortedSet&lt;E&gt;</code> interface and contains an instance of <code>SkipListInternal&lt;E&gt;</code>.</p>
  
  <p>Among other things, <code>SkipListInternal&lt;E&gt;</code> contains a method <code>E find(E e)</code> which returns the element equal to <code>e</code> if it is present, and otherwise returns null.</p>
  
  <p>When writing the <code>boolean contains(Object o)</code> (inherited from <code>Collection&lt;E&gt;</code> via <code>SortedSet&lt;E&gt;</code>) method I noticed that its argument is an Object and not an E. I intended to do something like this, but is not possible due to type erasure: </p>
  
  <pre><code>public class SkipListSet&lt;E&gt; implements SortedSet&lt;E&gt;{
     private SkipListInternal&lt;E&gt; skiplist;
  
     ...
  
     public boolean contains(Object o){
         if (!(o instanceof E)) return false;
         return skiplist.find((E) o) != null;
     }
  
     ...
  
  }
  </code></pre>
  
  <p>Since it can't be done this way, how should I do it?</p>