title: Why does this generic code compile in java 8?
body: <p>I've stumbled upon a piece of code that has me wondering why it compiles successfully:</p>
  
  <pre><code>public class Main {
      public static void main(String[] args) {
          String s =  newList(); // why does this line compile?
          System.out.println(s);
      }
  
      private static &lt;T extends List&lt;Integer&gt;&gt; T newList() {
          return (T) new ArrayList&lt;Integer&gt;();
      }
  }
  </code></pre>
  
  <p>What is interesting is that if I modify the signature of method <code>newList</code> with <code>&lt;T extends ArrayList&lt;Integer&gt;&gt;</code> it doesn't work anymore.</p>
  
  <p><strong>Update after comments &amp; responses:</strong>
  If I move the generic type from the method to the class the code doesn't compile anymore:</p>
  
  <pre><code>public class SomeClass&lt;T extends List&lt;Integer&gt;&gt; {
      public  void main(String[] args) {
          String s = newList(); // this doesn't compile anymore
          System.out.println(s);
      }
  
      private T newList() {
          return (T) new ArrayList&lt;Integer&gt;();
      }
  }
  </code></pre>