javac rejects valid java 7 code

Dan Smith daniel.smith at oracle.com
Thu Nov 21 09:43:35 PST 2013


On Nov 18, 2013, at 8:31 AM, Anna Kozlova <Anna.Kozlova at jetbrains.com> wrote:

> This code compiles with java 1.7 (also 1.6) but fails to compile with 1.8
> (b. 115)
> 
> 
> 
> abstract class A2<T>{
> 
>    abstract <S> S foo(S x, S y);
> 
>    abstract <S1> void baz(A2<S1> a)
> 
> 
> 
>    void bar(A2<Integer> y, A2<Long> x){
> 
>         baz(foo(x, y));
> 
>    }
> 
> }

Thanks for this example.  It illustrates a design flaw: inference in 8 supports capture on a nested method's return type (see Lambda Spec, Part G, 18.5.2), but only when the return type is a parameterized type.  As this example illustrates, it may also be necessary to perform capture when the return type is an inference variable (which can be instantiated to a parameterized type).

I've created a bug:
https://bugs.openjdk.java.net/browse/JDK-8028800

—Dan


More information about the lambda-dev mailing list