Re: reduction is too strict for ⟨MethodReference → alpha⟩

Dan Smith daniel.smith at oracle.com
Thu Dec 19 12:39:52 PST 2013


The argument should not be treated as pertinent to applicability.  This statement from 15.12.2.2 is meant to apply to exact method references too:

"If m is a generic method and the method invocation does not provide explicit type arguments, an explicitly-typed lambda expression ***or an exact method reference*** for which the corresponding target type (as derived from the signature of m) is a type parameter of m."

(The part in asterisks is currently missing.)

—Dan

On Dec 19, 2013, at 9:39 AM, Stephan Herrmann <stephan.herrmann at berlin.de> wrote:

> From this program
> 
>  interface Functional { int foo(); }
> 
>  class X {
>      static int bar() {
>          return -1;
>      }
>      static <T> T consume(T t) { return null; }
> 
>      public static void main(String[] args) {
>          Functional f = consume(X::bar);
>      }
>  }
> 
> we create this constraint:
> 
>  ⟨X::bar → T#0⟩
> 
> 18.2.1.2 says:
> 
> "If T is not a functional interface type (9.8), or if T is a functional interface type but does not have a function type, the constraint reduces to false."
> 
> Inference fails because T#0 (in inference variable) is not a functional interface type, nor does it have a sam.
> 
> javac accepts the program, so it seems to use an additional reduction rule here?
> 
> Stephan



More information about the lambda-spec-observers mailing list