aoqi@0: /* aoqi@0: * @test /nodynamiccopyright/ aoqi@0: * @bug 8029718 aoqi@0: * @summary Should always use lambda body structure to disambiguate overload resolution aoqi@0: * @compile/fail/ref=MostSpecific09.out -XDrawDiagnostics -XDshouldStopPolicy=ATTR -XDverboseResolution=applicable,success MostSpecific09.java aoqi@0: */ aoqi@0: aoqi@0: class MostSpecific09 { aoqi@0: aoqi@0: interface I { aoqi@0: String xoo(String x); aoqi@0: } aoqi@0: aoqi@0: interface J { aoqi@0: void xoo(int x); aoqi@0: } aoqi@0: aoqi@0: static void foo(I i) {} aoqi@0: static void foo(J j) {} aoqi@0: aoqi@0: static void moo(I i) {} aoqi@0: static void moo(J j) {} aoqi@0: aoqi@0: void m() { aoqi@0: foo((x) -> { return x += 1; }); aoqi@0: foo((x) -> { return ""; }); aoqi@0: foo((x) -> { System.out.println(""); }); aoqi@0: foo((x) -> { return ""; System.out.println(""); }); aoqi@0: foo((x) -> { throw new RuntimeException(); }); aoqi@0: foo((x) -> { while (true); }); aoqi@0: aoqi@0: foo((x) -> x += 1); aoqi@0: foo((x) -> ""); aoqi@0: } aoqi@0: aoqi@0: /* any return statement that is not in the body of the lambda but in an aoqi@0: * inner class or another lambda should be ignored for value void compatibility aoqi@0: * determination. aoqi@0: */ aoqi@0: void m1() { aoqi@0: boolean cond = true; aoqi@0: foo((x) -> { aoqi@0: if (cond) { aoqi@0: return ""; aoqi@0: } aoqi@0: System.out.println(""); aoqi@0: }); aoqi@0: aoqi@0: foo((x)->{ aoqi@0: class Bar { aoqi@0: String m() { aoqi@0: return "from Bar.m()"; aoqi@0: } aoqi@0: } aoqi@0: class Boo { aoqi@0: Bar b = new Bar (){ aoqi@0: String m() { aoqi@0: return "from Bar$1.m()"; aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: moo((y) -> { return ""; }); aoqi@0: return; aoqi@0: }); aoqi@0: aoqi@0: foo((x)->{ aoqi@0: class Bar { aoqi@0: void m() {} aoqi@0: } aoqi@0: class Boo { aoqi@0: Bar b = new Bar (){ aoqi@0: void m() { aoqi@0: return; aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: moo((y) -> { System.out.println(""); }); aoqi@0: return ""; aoqi@0: }); aoqi@0: } aoqi@0: }