Under JDK 8, the following program compiles and runs successfully.
Under JDK 11 and newer, it fails at runtime with a BootstrapMethodError.
I'd expect it to either be rejected by javac at compile-time, or succeed at runtime, but not compile and then fail at runtime.
This may be related to JDK-8269020, although that issue can be worked around by expressing the intersection bounds consistent, which doesn't apply to the following repro.
public class Z {
public static void main(String[] args) {
f();
}
static <T extends Comparable<T> & G> C<T> f() {
return new C<>(Q::g);
}
public interface G {}
private interface E<T> {
void g(Q g, T value);
}
static class C<T extends Comparable<?>> {
C(E<T> g) {}
}
static class Q {
void g(G g) {}
}
}
Exception in thread "main" java.lang.BootstrapMethodError: bootstrap method initialization exception
at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:194)
at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:307)
at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:258)
at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:248)
at Z.f(Z.java:9)
at Z.main(Z.java:5)
Caused by: java.lang.invoke.LambdaConversionException: Type mismatch for lambda argument 1: interface java.lang.Comparable is not convertible to interface Z$G
at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:279)
at java.base/java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:328)
at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:127)
... 5 more