Consider the following code fragment
String strings[] = {\"test\"};
final List collect = java.util.Arrays.stream(strings).collect(java.util.str
The signature of the method Stream::toArray looks as follows. Please note that the type parameters T and A are completely unrelated.
public interface Stream<T> {
<A> A[] toArray(IntFunction<A[]> generator);
}
In the source of ReferencePipeline.java, you can find the following comment:
Since
Ahas no relation toU(not possible to declare thatAis an upper bound ofU) there will be no static type checking. Therefore use a raw type and assumeA == Urather than propagating the separation ofAandUthroughout the code-base. The runtime type ofUis never checked for equality with the component type of the runtime type ofA[]. Runtime checking will be performed when an element is stored inA[], thus ifAis not a super type ofUanArrayStoreExceptionwill be thrown.