Neg14.java revision 2868:816bd88d33a8
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 */ 10class 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} 50