title: <? extends Class> and <? super Class> in Java - why it works this way?
body: <p>Yet another novice, trying to comprehend Java Generics.
  I've observed all topics, I found, but I still have huge questions.
  Could you please explain me the following things:</p>
  
  <ol>
  <li><code>&lt;? extends SomeClass&gt;</code> means, that <code>?</code> is "any type", and <code>extends SomeClass</code> means, that this any type can be only a subclass of <code>SomeClass</code>.
  OK, I write two elementary classes:</li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>abstract class Person {
      private String name;
      public Person(String name) {
          this.name = name;
      }
  }
  
  class Student extends Person {
      public Student(String name) {
          super(name);
      }
  }
  </code></pre>
  
  <p>Class <code>Student</code> will be <code>?</code> in our example. <code>? extends Person</code>, to be precise.
  Then I'm trying to add new student to ArrayList, that, as I understand from written above, applies all classes, that are subclasses of Person:</p>
  
  <pre class="lang-java prettyprint-override"><code>Student clarissa = new Student("Clarissa Starling");
  List&lt;? extends Person&gt; list = new ArrayList&lt;&gt;();
  list.add(clarissa); //Does not compile
  </code></pre>
  
  <p>Eclipse says:</p>
  
  <blockquote>
    <p>"The method add(capture#3-of ? extends Person) in the type
    List is not applicable for the
    arguments (Student)"</p>
  </blockquote>
  
  <p>How can class <code>Student</code> be not applicable, when we declared List, paramethrized by <code>&lt;? extends Person&gt;</code>, and <code>Student</code> exactly extends class <code>Person</code>?</p>
  
  <p>Nevertheless, the following code:</p>
  
  <pre class="lang-java prettyprint-override"><code>List&lt;? super Person&gt; list = new ArrayList&lt;&gt;();
  list.add(clarissa); 
  </code></pre>
  
  <p>compiles and works well (<code>list.get(0)</code>, passed to println method, shows me the correct result of <code>toString</code> invocation).
  As I understand, <code>List&lt;? super Person&gt;</code> means, that I can pass to this list any type, that is super type for our <code>Person</code> class (in our case it is <code>Object</code> class only). But we see, that, contrary to logic, we can easy add subclass Student to our <code>List&lt;? super Person&gt;</code>!</p>
  
  <p>OK, put aside our emotions, and let's see, what can happen with Clarissa Starling in our collection. Let's take our class <code>Student</code>, and add a couple of methods to it:</p>
  
  <pre class="lang-java prettyprint-override"><code>class Student extends Person {
      private int grant;
      public Student(String name) {
          super(name);
      }
  
      public void setGrant(int grant) {
          this.grant = grant;
      }
  
      public int getGrant() {
          return this.grant;
      }
  
  }
  </code></pre>
  
  <p>Then we pass an object, instantiated from this renewed class (our object "clarissa", for example), to <code>List&lt;? extends Person&gt;</code>. Doing this, we mean, that we can store subclass in the collection of its superclasses. Maybe, I don't understand some fundamenthal ideas, but at this stage I don't see any difference between adding subclass to the collection of its superclasses and the assigning of the reference to object "clarissa" to variable, typed Person. We have the same reducing of invokable methods, when we want to treat one of them, using our superclass variable. So, why <code>List&lt;? extends SomeClass&gt;</code> does not work the same way, wherein <code>List&lt;? super SomeClass&gt;</code> works conversely?</p>
  
  <ol start="2">
  <li>I don't understand the fundamenthal difference between <code>&lt;T&gt;</code> (or <code>&lt;E&gt;</code>, or any other letter from appropriate part of JLS) and <code>&lt;?&gt;</code>. Both <code>&lt;T&gt;</code> and <code>&lt;?&gt;</code> are <em>typeholders</em>, so why we have two "keywords" (this symbols are NOT keywords, I just used this word for emphasizing the heavy meaning of both symbols in Java language) for the same purpose?</li>
  </ol>