Diamonds: cyclic inference error
Remi Forax
forax at univ-mlv.fr
Mon Oct 15 11:15:10 PDT 2012
On 10/15/2012 07:25 PM, Maurizio Cimadamore wrote:
> On 15/10/12 17:52, Remi Forax wrote:
>> I'm not sure it's related to lambda,
>> I think it's more related to the way the inference works with the
>> diamond syntax,
>>
>> this code doesn't compile:
>> static <K,V> Map<K,V> foo(Map<K,V> map) {
>> return map;
>> }
>> ...
>> Map<String, String> map = foo(new HashMap<>());
>>
>> said differently, the rules introduced with Java 8 fix inference
>> introduced with Java 5
>> but not the one introduced with Java 7 (it will be fixed in Java 10 if
>> future follows the same pattern).
> I don't get the cynism here.
just cynism, sorry.
>
> Diamond is not the issue - the problem happens with all nested generic
> method calls where the target type contains one or more inference
> variable.
Yes, true, this doesn't compile.
static <K,V> Map<K,V> foo(Map<K,V> map) {
return map;
}
static <K,V> Map<K,V> end() {
return null;
}
...
Map<String, String> map2 = foo(end());
I think it should, basically, type constraints should be propagated.
>
> Maurizio
Rémi
More information about the lambda-dev
mailing list