diamond operator & implementation strategies (v3)

Rémi Forax forax at univ-mlv.fr
Mon Aug 24 18:04:06 PDT 2009

Le 24/08/2009 10:46, Maurizio Cimadamore a écrit :
>> 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

no arg constructor in method call => problem.
Correct me if I'm wrong but currently inference of method type 
parameters also fails.
So It's not a big deal.

> 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).

This example also fails in case of inference of method type parameter.
I think I prefer the complex inference algorithm because it works like 
the current method inference.

And in jdk8, we will see how to introduce the "complex on steroid" 
algorithm for both method and constructor inference.


More information about the coin-dev mailing list