Javac type inference issue

forax at forax at
Sun Aug 27 13:37:50 UTC 2023

> From: "attila kelemen85" <attila.kelemen85 at>
> To: "Remi Forax" <forax at>
> Cc: "compiler-dev" <compiler-dev at>
> Sent: Sunday, August 27, 2023 2:49:38 PM
> Subject: Re: Javac type inference issue

>> It's not a bug, it's how the capture works, a List<List<? super T>> is a List
>> where each List can have a different type, but here you want a List of List
>> with each list with the same type,
>> it can be approximated by

>> private static <T> void listMethod(List<? extends List<? super T>> list) {
>> }

> I think you misunderstand Rémi. I know very well what `List<List<? super T>>`
> is. And the code snippet I shared is logically correct in the sense that an
> infinitely intelligent type inferer could figure out that it is correct. In
> fact, if - in the above code - I write `Arrays.<List<? super T>>asList(args)`
> instead of `Arrays.asList(args)`, then it compiles fine. My question is why do
> I have to explicitly specify the type arguments, why can't it be inferred.

In case of a capture, the inference does not try to replace the capture by its bound. It's a limitation of the inference which tend to choose the most speciifc type where here, it has to use a less specific type. 

> Btw. If you change the `listMethod` argument to `List<? extends List<? super T>>
> list` it won't compile either.

My bad, I should have written List<? super List<? super T>>. 

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

More information about the compiler-dev mailing list