diamond operator & implementation strategies (v3)

Maurizio Cimadamore Maurizio.Cimadamore at Sun.COM
Mon Aug 24 01:46:51 PDT 2009


>
>
> Just a question, is there code that fails with the complex inference 
> algorithm
> that doesn't involve raw type/rare type ?
>   
Hi Remi,
to summarize, the complex approach can have problems when dealing with 
no arg constructors (quite common esp. with collections, see HashMap, 
ArrayList, ...)

In this case, the complex approach yields the same result given by the 
simple approach, as no inference from formals is possible:

class Foo<X> {
   Foo() {}
   static void m(Foo<Integer> fi) { ... }
}

m(new Foo<>()); //fails with both simple and complex

Another problematic situation can arise when the RHS type parameters are 
less specific than the actual arguments passed to the constructor:

class Foo<X> {
   Foo(X x) {}
}

Foo<Number> fn = new Foo<>(1); //simple succeeds (X==Number) - complex 
fails (X==Integer != Number).

Maurizio
> [...]
>
>   
>> Maurizio
>>    
>>     
>
> Rémi
>
>   




More information about the coin-dev mailing list