It is rare to say why the JDK API-interfaces have been developed as they did, but in this case we can easily see that the attempt to work together API-interface Stream<Integer>and IntStreamwill be challenging because the definitions of both interfaces method has several ambiguities.
Consider the following:
interface Stream<T> {
Stream<T> distinct();
Optional<T> findFirst();
}
interface IntStream extends Stream<Integer> {
IntStream distinct();
OptionalInt findFirst();
}
The second interface will not compile events, since the method signature is the same, but the return type is different in the second interface.
, , lambdas. Lambdas , . :
interface Stream<T> {
Stream<T> filter(Predicate<T> p);
<S> Stream<S> map(Function<T,S> mapper);
}
interface IntStream extends Stream<Integer> {
IntStream filter(IntPredicate p);
IntStream map(IntUnaryOperator mapper);
}
, , stream.filter(n -> n > 10), Predicate<Integer>, IntPredicate, API - , . (int n) -> n > 10, .
, API Stream IntStream.