1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/lambda/MostSpecific09.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,81 @@ 1.4 +/* 1.5 + * @test /nodynamiccopyright/ 1.6 + * @bug 8029718 1.7 + * @summary Should always use lambda body structure to disambiguate overload resolution 1.8 + * @compile/fail/ref=MostSpecific09.out -XDrawDiagnostics -XDshouldStopPolicy=ATTR -XDverboseResolution=applicable,success MostSpecific09.java 1.9 + */ 1.10 + 1.11 +class MostSpecific09 { 1.12 + 1.13 + interface I { 1.14 + String xoo(String x); 1.15 + } 1.16 + 1.17 + interface J { 1.18 + void xoo(int x); 1.19 + } 1.20 + 1.21 + static void foo(I i) {} 1.22 + static void foo(J j) {} 1.23 + 1.24 + static void moo(I i) {} 1.25 + static void moo(J j) {} 1.26 + 1.27 + void m() { 1.28 + foo((x) -> { return x += 1; }); 1.29 + foo((x) -> { return ""; }); 1.30 + foo((x) -> { System.out.println(""); }); 1.31 + foo((x) -> { return ""; System.out.println(""); }); 1.32 + foo((x) -> { throw new RuntimeException(); }); 1.33 + foo((x) -> { while (true); }); 1.34 + 1.35 + foo((x) -> x += 1); 1.36 + foo((x) -> ""); 1.37 + } 1.38 + 1.39 + /* any return statement that is not in the body of the lambda but in an 1.40 + * inner class or another lambda should be ignored for value void compatibility 1.41 + * determination. 1.42 + */ 1.43 + void m1() { 1.44 + boolean cond = true; 1.45 + foo((x) -> { 1.46 + if (cond) { 1.47 + return ""; 1.48 + } 1.49 + System.out.println(""); 1.50 + }); 1.51 + 1.52 + foo((x)->{ 1.53 + class Bar { 1.54 + String m() { 1.55 + return "from Bar.m()"; 1.56 + } 1.57 + } 1.58 + class Boo { 1.59 + Bar b = new Bar (){ 1.60 + String m() { 1.61 + return "from Bar$1.m()"; 1.62 + } 1.63 + }; 1.64 + } 1.65 + moo((y) -> { return ""; }); 1.66 + return; 1.67 + }); 1.68 + 1.69 + foo((x)->{ 1.70 + class Bar { 1.71 + void m() {} 1.72 + } 1.73 + class Boo { 1.74 + Bar b = new Bar (){ 1.75 + void m() { 1.76 + return; 1.77 + } 1.78 + }; 1.79 + } 1.80 + moo((y) -> { System.out.println(""); }); 1.81 + return ""; 1.82 + }); 1.83 + } 1.84 +}