langtools/test/tools/javac/generics/diamond/neg/Neg13.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 abstract super type
       
     6  * @author sadayapalam
       
     7  * @compile/fail/ref=Neg13.out Neg13.java -XDrawDiagnostics
       
     8  *
       
     9  */
       
    10 class Neg13 {
       
    11 
       
    12     static abstract class A<T> {
       
    13         abstract 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 abstract class 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 }