Unable to compile code using generics under 8u20 but builds under 8u05

Will May will.j.may at gmail.com
Mon Oct 13 12:47:31 UTC 2014


Hi all,

I've got a piece of code which will compile fine on JDK 8u05 but fails to
compile [1] on JDK 8u20; a minimal test case is at the bottom of this email.

I know that there were changes around generic wildcards in 8u20 but does
anyone know if 8u05 is bugged and it has been fixed or if 8u20 is now
bugged?

For reference, the two bugs that I found were fixed around generic
wildcards were 8042338 [2] and 8042803 [3].

Cheers,

Will.

1 The error message is "incompatible types:
java.util.function.Consumer<capture#1 of ?> cannot be converted to
java.util.function.Consumer<? super capture#1 of ?>"
2 https://bugs.openjdk.java.net/browse/JDK-8042338
3 https://bugs.openjdk.java.net/browse/JDK-8042803

import java.util.List;
import java.util.function.Consumer;

public class Temp {

    public void doWithList(final List<?> list) {
        list.stream().forEach(consumer(System.out::println));
    }

    @FunctionalInterface
    public static interface ExceptionThrowingConsumer<T> {
        void accept(T input) throws Exception;
    }

    public static <T> Consumer<T> consumer(ExceptionThrowingConsumer<T>
consumer) {
        return i -> {
            try {
                consumer.accept(i);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        };
    }

}


More information about the jdk8u-dev mailing list