title: Why is `Stream.collect` type-safe and `Stream.toArray(IntFunction<A[]>)` is not?
body: <p>Consider the following code fragment</p>
  
  <pre><code>String strings[] = {"test"};
  final List&lt;String&gt; collect = java.util.Arrays.stream(strings).collect(java.util.stream.Collectors.toList());
  final Double[] array = java.util.Arrays.stream(strings).toArray(Double[]::new);
  </code></pre>
  
  <p>Why can Java guarantee the correct type in the collect-case (changing the generic type of collect to e.g. Double leads to a compile time error), but not in the array case (compiles fine, despite <code>apply(int)</code> of <code>Double[]::new</code> gives a <code>Double[]</code>, not an <code>Object[]</code>, but throws <code>ArrayStoreException</code> if used incorrectly as above)?</p>
  
  <p>What would be the best way to generate a compile time error in case I change the type of the stream without changing the given <code>IntFunction</code> in the <code>toArray</code> call?</p>