test/tools/javac/generics/diamond/neg/Neg03.java

Mon, 07 Mar 2011 14:31:50 +0000

author
mcimadamore
date
Mon, 07 Mar 2011 14:31:50 +0000
changeset 914
ca32f2986301
parent 543
97b6fa97b8dd
child 2525
2eb010b6cb22
permissions
-rw-r--r--

7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
Summary: Disallow diamond on anonymous innner class creation expression (as per JSR 334's EDR)
Reviewed-by: jjg

     1 /*
     2  * @test /nodynamiccopyright/
     3  * @bug 6939620 7020044
     4  *
     5  * @summary  Check that diamond fails when inference violates declared bounds
     6  *           (test with inner class, qualified/simple type expressions)
     7  * @author mcimadamore
     8  * @compile/fail/ref=Neg03.out Neg03.java -XDrawDiagnostics
     9  *
    10  */
    12 class Neg03<U> {
    14     class Foo<V extends Number> {
    15         Foo(V x) {}
    16         <Z> Foo(V x, Z z) {}
    17     }
    19     void testSimple() {
    20         Foo<String> f1 = new Foo<>("");
    21         Foo<? extends String> f2 = new Foo<>("");
    22         Foo<?> f3 = new Foo<>("");
    23         Foo<? super String> f4 = new Foo<>("");
    25         Foo<String> f5 = new Foo<>("", "");
    26         Foo<? extends String> f6 = new Foo<>("", "");
    27         Foo<?> f7 = new Foo<>("", "");
    28         Foo<? super String> f8 = new Foo<>("", "");
    29     }
    31     void testQualified_1() {
    32         Foo<String> f1 = new Neg03<U>.Foo<>("");
    33         Foo<? extends String> f2 = new Neg03<U>.Foo<>("");
    34         Foo<?> f3 = new Neg03<U>.Foo<>("");
    35         Foo<? super String> f4 = new Neg03<U>.Foo<>("");
    37         Foo<String> f5 = new Neg03<U>.Foo<>("", "");
    38         Foo<? extends String> f6 = new Neg03<U>.Foo<>("", "");
    39         Foo<?> f7 = new Neg03<U>.Foo<>("", "");
    40         Foo<? super String> f8 = new Neg03<U>.Foo<>("", "");
    41     }
    43     void testQualified_2(Neg03<U> n) {
    44         Foo<String> f1 = n.new Foo<>("");
    45         Foo<? extends String> f2 = n.new Foo<>("");
    46         Foo<?> f3 = n.new Foo<>("");
    47         Foo<? super String> f4 = n.new Foo<>("");
    49         Foo<String> f5 = n.new Foo<>("", "");
    50         Foo<? extends String> f6 = n.new Foo<>("", "");
    51         Foo<?> f7 = n.new Foo<>("", "");
    52         Foo<? super String> f8 = n.new Foo<>("", "");
    53     }
    54 }

mercurial