1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/lambda/MethodReference22.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,67 @@ 1.4 +/* 1.5 + * @test /nodynamiccopyright/ 1.6 + * @bug 8003280 1.7 + * @summary Add lambda tests 1.8 + * check that pair of bound/non-bound method references checked correctly 1.9 + * @author Maurizio Cimadamore 1.10 + * @compile/fail/ref=MethodReference22.out -XDrawDiagnostics MethodReference22.java 1.11 + */ 1.12 + 1.13 +class MethodReference22 { 1.14 + 1.15 + void m1(String x) { } 1.16 + void m1(MethodReference22 rec, String x) { } 1.17 + 1.18 + static void m2(String x) { } 1.19 + static void m2(MethodReference22 rec, String x) { } 1.20 + 1.21 + static void m3(String x) { } 1.22 + void m3(MethodReference22 rec, String x) { } 1.23 + 1.24 + void m4(String x) { } 1.25 + static void m4(MethodReference22 rec, String x) { } 1.26 + 1.27 + interface SAM1 { 1.28 + void m(String x); 1.29 + } 1.30 + 1.31 + interface SAM2 { 1.32 + void m(MethodReference22 rec, String x); 1.33 + } 1.34 + 1.35 + static void call1(SAM1 s) { } 1.36 + 1.37 + static void call2(SAM2 s) { } 1.38 + 1.39 + static void call3(SAM1 s) { } 1.40 + static void call3(SAM2 s) { } 1.41 + 1.42 + static void test1() { 1.43 + SAM1 s1 = MethodReference22::m1; //fail 1.44 + call1(MethodReference22::m1); //fail 1.45 + SAM1 s2 = MethodReference22::m2; //ok 1.46 + call1(MethodReference22::m2); //ok 1.47 + SAM1 s3 = MethodReference22::m3; //ok 1.48 + call1(MethodReference22::m3); //ok 1.49 + SAM1 s4 = MethodReference22::m4; //fail 1.50 + call1(MethodReference22::m4); //fail 1.51 + } 1.52 + 1.53 + static void test2() { 1.54 + SAM2 s1 = MethodReference22::m1; //ok 1.55 + call2(MethodReference22::m1); //ok 1.56 + SAM2 s2 = MethodReference22::m2; //ok 1.57 + call2(MethodReference22::m2); //ok 1.58 + SAM2 s3 = MethodReference22::m3; //fail 1.59 + call2(MethodReference22::m3); //fail 1.60 + SAM2 s4 = MethodReference22::m4; //fail 1.61 + call2(MethodReference22::m4); //fail 1.62 + } 1.63 + 1.64 + static void test3() { 1.65 + call3(MethodReference22::m1); //ok 1.66 + call3(MethodReference22::m2); //ambiguous 1.67 + call3(MethodReference22::m3); //ok 1.68 + call3(MethodReference22::m4); //fail 1.69 + } 1.70 +}