test/tools/javac/lambda/TargetType21.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 3938
93012e2a5d1d
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe

aoqi@0 1 /*
aoqi@0 2 * @test /nodynamiccopyright/
aoqi@0 3 * @bug 8003280
aoqi@0 4 * @summary Add lambda tests
aoqi@0 5 * check that candidates with cyclic type-inference are removed from the
aoqi@0 6 * set of applicable methods
aoqi@0 7 * @compile/fail/ref=TargetType21.out -XDrawDiagnostics TargetType21.java
aoqi@0 8 */
aoqi@0 9
aoqi@0 10 class TargetType21 {
aoqi@0 11 interface SAM1 {
aoqi@0 12 String m1(Integer n) throws Exception;
aoqi@0 13 }
aoqi@0 14
aoqi@0 15 interface SAM2 {
aoqi@0 16 void m2(Integer n);
aoqi@0 17 }
aoqi@0 18
aoqi@0 19 interface SAM3<R,A> {
aoqi@0 20 R m3(A n);
aoqi@0 21 }
aoqi@0 22
aoqi@0 23 void call(SAM1 sam) { }
aoqi@0 24 void call(SAM2 sam) { }
aoqi@0 25 <R,A> void call(SAM3<R,A> sam) { }
aoqi@0 26
aoqi@0 27 void test() {
aoqi@0 28 call(x -> { throw new Exception(); }); //ambiguous
aoqi@0 29 call((Integer x) -> { System.out.println(""); }); //ok (only one is void)
aoqi@0 30 call((Integer x) -> { return (Object) null; }); //ok (only one returns Object)
aoqi@0 31 call(x -> { System.out.println(""); }); //ambiguous
aoqi@0 32 call(x -> { return (Object) null; }); //ambiguous
aoqi@0 33 call(x -> { return null; }); //ambiguous
aoqi@0 34 }
aoqi@0 35 }

mercurial