question about enhanced type-inference

Dan Smith daniel.smith at
Thu Nov 21 12:51:01 PST 2013

The fact that this compiles in 7 is an implementation quirk.  During overload resolution, the compiler is supposed to decide that the method is applicable by (tentatively) inferring E and T while ignoring the assignment target.  javac cannot do this (as you can see if you comment out the assignment), but cheats by not really fully inferring E and T.

We haven't considered this a JLS compliance bug because JLS is pretty vague about how this process is supposed to work, leaving expected behavior open to interpretation.

In 8, the spec has been tightened and it's now clear that E and T must be (tentatively) inferred independent of the assignment target.  Since the 8 algorithm is not powerful enough to perform that inference, the error occurs.

The specific problem -- inference is not smart enough to conclude that
t <: Task<e>
t <: Task<CustomException>
e = CustomException

However, it does seem plausible that an inference rule could be added to handle this.  Since this falls somewhere in the space between "bug" and "feature request", I'll consider it...

Here's my spec bug:


On Nov 19, 2013, at 11:16 AM, Liam Miller-Cushon <cushon at> wrote:

> I have been experimenting with migrating some code to compile with javac
> 8's new graph inference algorithm. This has generally gone quite smoothly,
> but I ran into the following case where inference succeeds with legacy
> inference and fails with graph inference.
> Is this a known limitation of the new inference algorithm?
> Here's the code:
> ===
> interface Task<E extends Exception> {}
> class Comparator<T> {}
> class CustomException extends Exception {}
> class TaskQueue<E extends Exception, T extends Task<E>> {}
> abstract class Test {
>  abstract <E extends Exception, T extends Task<E>>
>      TaskQueue<E, T> create(Comparator<? super T> comparator);
>  void f(Comparator<Task<CustomException>> comp) {
>    TaskQueue<CustomException, Task<CustomException>> queue = create(comp);
>  }
> }
> ===

More information about the lambda-dev mailing list