Generics type inference problem?

Attila Kelemen attila.kelemen85 at
Sun Jun 11 16:16:49 UTC 2017


I'm not sure if my issue is a violation of the specs or a bug, so I'm
writing here instead of a bug report. The following class does not compile
(imports are omitted) in Java 9 but does in Java 8:

    public final class NewClass {
        private static <E extends Throwable> List<TestFactory<E>> test(
                Collection<? extends Supplier<? extends E>> factory) {

        private static <E extends Throwable> TestFactory<E>
testMap(Supplier<? extends E> factory) {
            return null;

        private static interface TestFactory<E extends Throwable> {

The above `test` method does not compile because type inference fails to
deduce the "appropriate" type for the return value of `Stream.collect`.
Which is strange given that `` should map to
`Stream<TestFactory<E>>`. In fact, if I rewrite the method `test` to:

        Stream<TestFactory<E>> factoryStream =;
        return factoryStream.collect(Collectors.toList());

The code will compile fine.

Is this behaviour in accordance with the spec or is this a bug?

The exact versions I have tried this with:

Java 8: java version "1.8.0_92", build 1.8.0_92-b14
Java 9: java version "9-ea", build 9-ea+170

Attila Kelemen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the compiler-dev mailing list