FULL PRODUCT VERSION : java version "1.8.0_05" Java(TM) SE Runtime Environment (build 1.8.0_05-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) ADDITIONAL OS VERSION INFORMATION : Linux 3.4.69-desktop-1.mga2 #1 SMP Sat Nov 16 17:32:02 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux A DESCRIPTION OF THE PROBLEM : The JLS8 chapter 15.12.2.2 describes that an explicitly-typed lambda should be considered not pertinent to applicability if at least one of the return expressions is not pertinent to applicability. If an explicitly-typed lambda returns some implicitly-typed lambda, it sometimes behaves like it is considered pertinent to applicability anyway, for example if the implicitly-typed lambda is returned from inside an if-statement. ADDITIONAL REGRESSION INFORMATION: java version "1.8.0_05" Java(TM) SE Runtime Environment (build 1.8.0_05-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Compile the test case supplied. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - Compilation was expected to fail. ACTUAL - Compilation succeeded. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- public class Test { interface A { B m(int a, int b); } interface C { String m(int a, int b); } interface B { int m(int c); } public static void method(A a) { System.out.println("Method 1"); } public static void method(C c) { System.out.println("Method 2"); } public static void main(String[] args) { // This succeeds method((int a, int b) -> { if(a < b) return c -> a + b + c; else return c -> a + b + c; }); /*But this fails (as expected) method((int a, int b) -> { return c -> a + b + c; });*/ } } ---------- END SOURCE ----------
|