Sat, 22 Dec 2018 13:10:38 -0800
Added tag jdk8u202-b25 for changeset 15d8c732039b
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 non-compatible method references are rejected |
aoqi@0 | 6 | * @compile/fail/ref=MethodReference28.out -XDrawDiagnostics MethodReference28.java |
aoqi@0 | 7 | */ |
aoqi@0 | 8 | |
aoqi@0 | 9 | class MethodReference28 { |
aoqi@0 | 10 | |
aoqi@0 | 11 | interface SAM1 { |
aoqi@0 | 12 | void m(int i); |
aoqi@0 | 13 | } |
aoqi@0 | 14 | |
aoqi@0 | 15 | interface SAM2 { |
aoqi@0 | 16 | void m(MethodReference28 rec, int i); |
aoqi@0 | 17 | } |
aoqi@0 | 18 | |
aoqi@0 | 19 | static void static_m1(Integer i) { } //ok - boxing |
aoqi@0 | 20 | static void static_m2(Integer i1, Integer i2) { } //wrong arity |
aoqi@0 | 21 | static void static_m3(String s) { } //type mismatch |
aoqi@0 | 22 | static void static_m4(String... ss) { } //type mismatch - varargs |
aoqi@0 | 23 | |
aoqi@0 | 24 | void m1(Integer i) { } //ok - boxing |
aoqi@0 | 25 | void m2(Integer i1, Integer i2) { } //wrong arity |
aoqi@0 | 26 | void m3(String s) { } //type mismatch |
aoqi@0 | 27 | void m4(String... ss) { } //type mismatch - varargs |
aoqi@0 | 28 | |
aoqi@0 | 29 | static void testStatic() { |
aoqi@0 | 30 | SAM1 s1 = MethodReference28::static_m1; |
aoqi@0 | 31 | SAM1 s2 = MethodReference28::static_m2; |
aoqi@0 | 32 | SAM1 s3 = MethodReference28::static_m3; |
aoqi@0 | 33 | SAM1 s4 = MethodReference28::static_m4; |
aoqi@0 | 34 | } |
aoqi@0 | 35 | |
aoqi@0 | 36 | void testBadMember() { |
aoqi@0 | 37 | SAM1 s1 = MethodReference28::m1; |
aoqi@0 | 38 | SAM1 s2 = MethodReference28::m2; |
aoqi@0 | 39 | SAM1 s3 = MethodReference28::m3; |
aoqi@0 | 40 | SAM1 s4 = MethodReference28::m4; |
aoqi@0 | 41 | } |
aoqi@0 | 42 | |
aoqi@0 | 43 | void testMember() { |
aoqi@0 | 44 | SAM1 s1 = this::m1; |
aoqi@0 | 45 | SAM1 s2 = this::m2; |
aoqi@0 | 46 | SAM1 s3 = this::m3; |
aoqi@0 | 47 | SAM1 s4 = this::m4; |
aoqi@0 | 48 | } |
aoqi@0 | 49 | |
aoqi@0 | 50 | static void testUnbound() { |
aoqi@0 | 51 | SAM2 s1 = MethodReference28::m1; |
aoqi@0 | 52 | SAM2 s2 = MethodReference28::m2; |
aoqi@0 | 53 | SAM2 s3 = MethodReference28::m3; |
aoqi@0 | 54 | SAM2 s4 = MethodReference28::m4; |
aoqi@0 | 55 | } |
aoqi@0 | 56 | } |