test/tools/javac/lambda/MostSpecific12.java

Tue, 29 Mar 2016 10:48:49 +0000

author
dbuck
date
Tue, 29 Mar 2016 10:48:49 +0000
changeset 3102
e74dd6df4d4c
parent 0
959103a6100f
permissions
-rw-r--r--

8143647: Javac compiles method reference that allows results in an IllegalAccessError
Summary: Lambda implementation method synthesized by javac should not mention inaccessible types.
Reviewed-by: mcimadamore

     1 /*
     2  * @test /nodynamiccopyright/
     3  * @bug 8034223
     4  * @summary Most-specific testing with inference variables in function parameter types
     5  * @compile/fail/ref=MostSpecific12.out -XDrawDiagnostics MostSpecific12.java
     6  */
     7 class MostSpecific12 {
     9     interface I<T> { void take(T arg1, String arg2); }
    10     interface J<T> { void take(String arg1, T arg2); }
    11     interface K { void take(String arg1, String arg2); }
    13     <T> void m1(I<T> arg) {}
    14     void m1(K arg) {}
    16     <T> void m2(J<T> arg) {}
    17     <T> void m2(K arg) {}
    19     <T> void m3(I<T> arg) {}
    20     <T> void m3(J<T> arg) {}
    22     void test() {
    23         m1((String s1, String s2) -> {}); // ok
    24         m2((String s1, String s2) -> {}); // ok
    25         m3((String s1, String s2) -> {}); // error
    27         m1(this::referencedMethod); // ok
    28         m2(this::referencedMethod); // ok
    29         m3(this::referencedMethod); // error
    31         m1(String::compareTo); // ok
    32         m2(String::compareTo); // ok
    33         m3(String::compareTo); // error
    34     }
    36     void referencedMethod(String s1, String s2) {}
    38 }

mercurial