test/tools/javac/lambda/MethodReference22.java

changeset 0
959103a6100f
child 1610
08782b8b03ce
equal deleted inserted replaced
-1:000000000000 0:959103a6100f
1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8003280
4 * @summary Add lambda tests
5 * check that pair of bound/non-bound method references checked correctly
6 * @author Maurizio Cimadamore
7 * @compile/fail/ref=MethodReference22.out -XDrawDiagnostics MethodReference22.java
8 */
9
10 class MethodReference22 {
11
12 void m1(String x) { }
13 void m1(MethodReference22 rec, String x) { }
14
15 static void m2(String x) { }
16 static void m2(MethodReference22 rec, String x) { }
17
18 static void m3(String x) { }
19 void m3(MethodReference22 rec, String x) { }
20
21 void m4(String x) { }
22 static void m4(MethodReference22 rec, String x) { }
23
24 interface SAM1 {
25 void m(String x);
26 }
27
28 interface SAM2 {
29 void m(MethodReference22 rec, String x);
30 }
31
32 static void call1(SAM1 s) { }
33
34 static void call2(SAM2 s) { }
35
36 static void call3(SAM1 s) { }
37 static void call3(SAM2 s) { }
38
39 static void test1() {
40 SAM1 s1 = MethodReference22::m1; //fail
41 call1(MethodReference22::m1); //fail
42 SAM1 s2 = MethodReference22::m2; //ok
43 call1(MethodReference22::m2); //ok
44 SAM1 s3 = MethodReference22::m3; //ok
45 call1(MethodReference22::m3); //ok
46 SAM1 s4 = MethodReference22::m4; //fail
47 call1(MethodReference22::m4); //fail
48 }
49
50 static void test2() {
51 SAM2 s1 = MethodReference22::m1; //ok
52 call2(MethodReference22::m1); //ok
53 SAM2 s2 = MethodReference22::m2; //ok
54 call2(MethodReference22::m2); //ok
55 SAM2 s3 = MethodReference22::m3; //fail
56 call2(MethodReference22::m3); //fail
57 SAM2 s4 = MethodReference22::m4; //fail
58 call2(MethodReference22::m4); //fail
59 }
60
61 static void test3() {
62 call3(MethodReference22::m1); //ok
63 call3(MethodReference22::m2); //ambiguous
64 call3(MethodReference22::m3); //ok
65 call3(MethodReference22::m4); //fail
66 }
67 }

mercurial