title: Cast list of Object to list of class' type parameter
body: <p>I'm trying to understanding the different compilation outcome of seemingly analogous code. It appears it is possible to cast a <code>List&lt;Object&gt;</code> to a <code>List&lt;T&gt;</code> but only if <code>T</code> isn't bounded by a concrete class. So given...</p>
  
  <pre><code>List&lt;Object&gt; bis = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>The following compiles in <code>class Test&lt;T&gt;</code> as well as in <code>class Test&lt;T extends CharSequence&gt;</code> but not in <code>class Test&lt;T extends BigDecimal&gt;</code> nor <code>class Test&lt;T extends BigDecimal &amp; CharSequence&gt;</code>.</p>
  
  <pre><code>List&lt;T&gt; result = (List&lt;T&gt;) bis;
  </code></pre>
  
  <p>So where does the difference come from for <code>T</code> bounded with a class type and an interface type?</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>Some complete code per request. This compiles with a compiler warning in line 9. It's indeed unsafe as operating on items of <code>result</code> as if they were instances of <code>CharSequence</code> results in a <code>ClassCastException</code>.</p>
  
  <pre><code>    public class Sandbox&lt;T extends CharSequence&gt; {
  
      public static void main(String[] args) {
          new Sandbox&lt;CharSequence&gt;().foo();
      }
  
      private void foo() {    
          List&lt;Object&gt; bis = Arrays.asList(Integer.valueOf(1));
          List&lt;T&gt; result = (List&lt;T&gt;) bis;
          System.out.println(result);
      }
  }
  </code></pre>
  
  <p>However, this doesn't compile at all:</p>
  
  <pre><code>    public class Sandbox&lt;T extends BigDecimal&gt; {
  
      public static void main(String[] args) {
          new Sandbox&lt;BigDecimal&gt;().foo();
      }
  
      private void foo() {    
          List&lt;Object&gt; bis = Arrays.asList(Integer.valueOf(1));
          List&lt;T&gt; result = (List&lt;T&gt;) bis;
          System.out.println(result);
      }
  
  }
  </code></pre>
  
  <p>Compiler error in line 9: Cannot cast <code>List&lt;Object&gt;</code> to <code>List&lt;T&gt;</code>.</p>