title: isInstance & instanceof - Why there's no generic way?
body: <p>I understand the usage &amp; motive of both of these - isInstance is Runtime Equivalent of instanceOf.But , why do we have two ways?
  Why could not we have a generic implementation of instanceof keyword which caters to both the cases?</p>
  
  <p>For Example , this is the way these are used currently: </p>
  
  <h2>1)instanceof</h2>
  
  <pre><code>public Collection&lt;String&gt; extract(Collection&lt;?&gt; coll) {
      Collection&lt;String&gt; result = new ArrayList&lt;String&gt;();
      for (Object obj : coll) {
        if (obj instanceof String) {
          result.add((String) obj);
        }
      }
      return result;
  }
  </code></pre>
  
  <h2>2)isInstance</h2>
  
  <pre><code>public &lt;T&gt; Collection&lt;T&gt; extract(Collection&lt;?&gt; coll, Class&lt;T&gt; type) {
      Collection&lt;T&gt; result = new ArrayList&lt;T&gt;();
      for (Object obj : coll) {
        if (type.isInstance(obj)) {
          result.add((T) obj);
        }
      }
      return result;
  }
  </code></pre>
  
  <p>So , my Question is why can't we have a generic implementation of instanceof operator that caters to the 2nd exmaple above as below? (i.e. Why can't it resolve the type at runtime?)</p>
  
  <pre><code>public &lt;T&gt; Collection&lt;T&gt; extract(Collection&lt;?&gt; coll, Class&lt;T&gt; type) {
      Collection&lt;T&gt; result = new ArrayList&lt;T&gt;();
      for (Object obj : coll) {
        if (obj instanceof type) {
          result.add((T) obj);
        }
      }
      return result;
  }
  </code></pre>