lambda in result expression of explicitly typed lambda

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Feb 12 22:12:50 UTC 2015


On 12/02/15 19:51, Anna Kozlova wrote:
> Hi,
>
> Consider the following code:
>     
>     {
>           Supplier<Runnable > x = foo (() ->  () -> {});
>      }
>
>      static <T> Supplier<T> foo(Supplier<T> delegate) {
>          return null;
>      }
>
> At the applicability check phase I expect B2 to contain <() -> {} -> T>,  and according to 18.2.1 it reduces to false ("If T is not a functional interface type (§9.8), the constraint reduces to false").
> However 8u40 b23 compiles the code just fine, but why?
I think it's an issue of timing - i.e. 18.2.1 should not be applied to 
non-proper types; I believe it should only be applied after you inferred 
T to be Runnable (form the target) and then incorporated the result into 
the method target (which then becomes Supplier<Runnable>, and 18.2.1 is 
happy). The reason as to why 18.2.1 is 'deferred' is buried inside 
18.5.2 - long story short, the constraint () -> () -> {}  --> 
Supplier<T> cannot be looked into because it depends on an input 
inference variable, namely T. Since the constraints formula is not 
evaluated, 18.2.1 doesn't kick in at this stage.

Maurizio
>
> Thank you,
> Anna
>



More information about the compiler-dev mailing list