Notes on implementing concise calls to constructors with type parameters

Maurizio Cimadamore Maurizio.Cimadamore at Sun.COM
Thu May 14 02:17:47 PDT 2009


> List<Number> ln = new ArrayList<>(1);
>
> This would be inferred to ArrayList<Number> with my proposal; with your 
> proposal the above code will be flagged with an error, as the inferred 
> type ArrayList<Integer> (which I agree is more specific) is not 
> compatible with the expected type List<Number>. The only alternative 
> would be to use a wildcard in the LHS.
>   
Whoops! This example is obviously wrong as no such constructor is 
defined in ArrayList. Instead what I meant was:

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


Foo<Number> fn = new Foo<>();

the above statement compiles iff Foo<> is inferred as Foo<Number>.

Maurizio



More information about the coin-dev mailing list