New behavior : java: incompatible types: inferred type does not conform to upper bound(s)
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Jan 7 00:59:29 PST 2013
On 01/01/13 15:34, Boaz Nahum wrote:
> Hi.
>
> Old code is no longer compiled (I built lambda/lambda today 1-1-2013)
>
> static class F<T> {}
>
> static <T> T get(F<T> f) {return null;}
> F<Integer> fi = new F<>();
>
>
> double d1 = get(fi);
>
> The last line yields
>
> java: incompatible types: inferred type does not conform to upper bound(s)
> inferred: java.lang.Integer
> upper bound(s): java.lang.Double,java.lang.Object
This is a side-effect of some inference improvements we have made; we
now wait to see the target type before instantiating method
type-parameters, which allows the right thing to happen in cases like:
class Cell<X> {
Cell(X x) { ... }
}
Cell<Number> c = new Cell<>(1); //fails with JDK 7
I think your example shows there're still some improvements to be made
around handling of primitives
Maurizio
>
> Only casting solve the problem:
>
> double d1 = (int)get(fi);
> double d1 = (double)get(fi);
>
>
> Happy new year
> Boaz
>
More information about the lambda-dev
mailing list