title: Java method with parameterized list type parameter
body: <p>Let's say we have two classes Parent and Child:</p>
  <pre><code>public class Parent {
  }
  
  public class Child extends Parent {
  }
  </code></pre>
  <p>And we have method with following argument:</p>
  <pre><code>public void foo(List&lt;Parent&gt; list) {
  ...
  }
  </code></pre>
  <p>My question why is following method arguments is illegal(case A)</p>
  <pre><code>List&lt;Child&gt; list = List.of(new Child());
  foo(list); //compile error
  </code></pre>
  <p>but at the same time such case is valid(case B)</p>
  <pre><code>foo(List.of(new Child());
  </code></pre>
  <p><code>List.of()</code> has such signature <code>static &lt;E&gt; List&lt;E&gt; of(E... elements)</code>, so i expect that
  <code>List.of(new Child())</code> has type <code>List&lt;Child&gt;</code> and because of <a href="https://docs.oracle.com/javase/tutorial/java/generics/subtyping.html" rel="nofollow noreferrer">this wildcard rule</a>(<code>List&lt;Child&gt;</code> not extends <code>List&lt;Parent&gt;</code>) i think that both cases must not compile.</p>
  <p>But why case B compiles? Compiler sees, that <code>List.of(new Child())</code> doesn't have explicit type and checks that every item of list can be casted to <code>Parent.class</code> and do it to obtain correct type?</p>