title: Why do the new Java 8 streams return an Object Array on toArray calls?
body: <p>Whilst I was working on a project involving Java 8's new streams, I noticed that when I called <code>Stream#toArray()</code> on a stream, it return an <code>Object[]</code> instead of a <code>T[]</code>. Surprised as I was, I started digging into the source code of Java 8 and couldn't find any reason why they didn't implement <code>Object[] toArray();</code> as <code>T[] toArray();</code>. Is there any reasoning behind this, or is it just an (in)consistency? </p>
  
  <p>EDIT 1:
  I noticed in the answers that a lot of people said this would not be possible, but this code snippet compiles and return the expected result?</p>
  
  <pre><code>import java.util.Arrays;
  
  public class Test&lt;R&gt; {
  
      private Object[] items;
  
      public Test(R[] items) {
          this.items = items;
      }
  
      public R[] toArray() {
          return (R[]) items;
      }
  
      public static void main(String[] args) {
          Test&lt;Integer&gt; integerTest = new Test&lt;&gt;(new Integer[]{
              1, 2, 3, 4
          });
  
          System.out.println(Arrays.toString(integerTest.toArray()));
      }
  
  }
  </code></pre>