title: what's wrong with my generic type casting?
body: <p>I have a <code>Student</code> class and a <code>StudentPool</code> class defined as follows:</p>
  
  <pre><code>public class Student {
      public Student copy () {
          return new Student();
      } 
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class StudentPool&lt;T extends Student&gt; {
      public T copyStudent(T t) {
          return t.copy();
      }
  }
  </code></pre>
  
  <p>thus, the <code>copyStudent</code> method cannot be compiled and I have to use un-safe type casting. I cannot understand why Java does regard this as illegal?</p>
  
  <p><strong>Edit:</strong>
  user845279, lcfseth, and Bohemian: I think the following revision to Student may cause the similar scenario, cast a parent class into its child class, but this version can pass compiling:</p>
  
  <pre><code>public class Student {
      public &lt;T extends Student&gt; T copy() {
         T rv = null; 
         return rv;
      } 
  }
  </code></pre>
  
  <p><strong>Edit:</strong>
  forget the above code: <code>rv</code> can be either <code>null</code> or un-safely casted.</p>