test/tools/javac/lambda/MethodReference28.java

changeset 0
959103a6100f
equal deleted inserted replaced
-1:000000000000 0:959103a6100f
1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8003280
4 * @summary Add lambda tests
5 * check that non-compatible method references are rejected
6 * @compile/fail/ref=MethodReference28.out -XDrawDiagnostics MethodReference28.java
7 */
8
9 class MethodReference28 {
10
11 interface SAM1 {
12 void m(int i);
13 }
14
15 interface SAM2 {
16 void m(MethodReference28 rec, int i);
17 }
18
19 static void static_m1(Integer i) { } //ok - boxing
20 static void static_m2(Integer i1, Integer i2) { } //wrong arity
21 static void static_m3(String s) { } //type mismatch
22 static void static_m4(String... ss) { } //type mismatch - varargs
23
24 void m1(Integer i) { } //ok - boxing
25 void m2(Integer i1, Integer i2) { } //wrong arity
26 void m3(String s) { } //type mismatch
27 void m4(String... ss) { } //type mismatch - varargs
28
29 static void testStatic() {
30 SAM1 s1 = MethodReference28::static_m1;
31 SAM1 s2 = MethodReference28::static_m2;
32 SAM1 s3 = MethodReference28::static_m3;
33 SAM1 s4 = MethodReference28::static_m4;
34 }
35
36 void testBadMember() {
37 SAM1 s1 = MethodReference28::m1;
38 SAM1 s2 = MethodReference28::m2;
39 SAM1 s3 = MethodReference28::m3;
40 SAM1 s4 = MethodReference28::m4;
41 }
42
43 void testMember() {
44 SAM1 s1 = this::m1;
45 SAM1 s2 = this::m2;
46 SAM1 s3 = this::m3;
47 SAM1 s4 = this::m4;
48 }
49
50 static void testUnbound() {
51 SAM2 s1 = MethodReference28::m1;
52 SAM2 s2 = MethodReference28::m2;
53 SAM2 s3 = MethodReference28::m3;
54 SAM2 s4 = MethodReference28::m4;
55 }
56 }

mercurial