reduction is too strict for ⟨MethodReference → alpha⟩

Stephan Herrmann stephan.herrmann at berlin.de
Thu Dec 19 08:39:59 PST 2013


 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-experts mailing list