Change in type inference behaviour with JDK-8078024

Liam Miller-Cushon cushon at google.com
Tue Jul 7 21:34:46 UTC 2015


The fix for JDK-8078024 resolved an issue with type inference I was seeing
with javac9. I can't tell from the bug report if that was deliberate.

Could someone please confirm that the current behaviour is correct?

Here's the repro. It fails with jdk9-dev @2888, and compiles cleanly @2889:

=== A.java ===
import java.util.Arrays;
import java.util.List;

class A {
  public static <B> List<List<B>> cartesianProduct(List<? extends B>...
lists) {
    return cartesianProduct(Arrays.asList(lists));
  }

  public static <B> List<List<B>> cartesianProduct(List<? extends List<?
extends B>> lists) {
    throw new AssertionError();
  }
}
===

$ javac A.java
A.java:6: error: incompatible types: inference variable B has incompatible
bounds
    return cartesianProduct(Arrays.asList(lists));
                           ^
    equality constraints: B
    lower bounds: T,List<? extends B>
  where B,T are type-variables:
    B extends Object declared in method <B>cartesianProduct(List<? extends
B>...)
    T extends Object declared in method <T>asList(T...)
Note: /usr/local/google/home/cushon/A.java uses unchecked or unsafe
operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150707/ae066429/attachment.html>


More information about the compiler-dev mailing list