langtools/test/tools/javac/generics/diamond/neg/Neg14.java
changeset 29776 984a79b71cfe
equal deleted inserted replaced
29775:dc7df633fea1 29776:984a79b71cfe
       
     1 /*
       
     2  * @test /nodynamiccopyright/
       
     3  * @bug 8062373
       
     4  *
       
     5  * @summary  Test diamond + anonymous classes with super type being an interface.
       
     6  * @author sadayapalam
       
     7  * @compile/fail/ref=Neg14.out Neg14.java -XDrawDiagnostics
       
     8  *
       
     9  */
       
    10 class Neg14 {
       
    11 
       
    12     static interface A<T> {
       
    13         void foo();
       
    14     }
       
    15 
       
    16     static void foo(A<String> as) {}
       
    17 
       
    18     public static void main(String[] args) {
       
    19 
       
    20         // Method invocation context - good <>(){}
       
    21         foo(new A<>() {
       
    22             public void foo() {}
       
    23         });
       
    24 
       
    25         // Assignment context - good <>(){}
       
    26         A<?> aq = new A<>() {
       
    27             public void foo() {}
       
    28         };
       
    29 
       
    30         // When the anonymous type subtypes an interface but is missing definitions for
       
    31         // abstract methods, expect no overload resolution error, but an attribution error
       
    32         // while attributing anonymous class body.
       
    33 
       
    34 
       
    35         // Method invocation context - bad <>(){}
       
    36         foo(new A<>() {
       
    37         });
       
    38 
       
    39         // Assignment invocation context - bad <>(){}
       
    40         aq = new A<>() {
       
    41         };
       
    42 
       
    43         // Method invocation context - bad <>()
       
    44         foo(new A<>());
       
    45 
       
    46         // Assignment invocation context - bad <>()
       
    47         aq = new A<>();
       
    48     }
       
    49 }