title: why instanceof does not work with Generic?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1570073/java-instanceof-and-generics">Java: Instanceof and Generics</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to write a function which cast a generic List to specific type List. Find the code below </p>
  
  <pre><code>public &lt;T&gt;List&lt;T&gt; castCollection(List srcList, Class&lt;T&gt; clas){
      List&lt;T&gt; list =new ArrayList&lt;T&gt;();
      for (Object obj : srcList) {
         if(obj instanceof T){
              ...
         }
      }
      return list;
  }
  </code></pre>
  
  <p>But <code>obj instanceof T</code> showing a compilation error - </p>
  
  <blockquote>
    <p>Cannot perform instanceof check against type parameter T. Use instead its erasure Object >instead since further generic type information will be erased at runtime.</p>
  </blockquote>
  
  <p>any clarification or way to get the desired result?</p>
  
  <p>Thanks in advance. :)</p>