langtools/test/tools/javac/generics/diamond/neg/Neg12.java
author sadayapalam
Thu, 26 Nov 2015 17:38:15 +0530
changeset 34474 14deea5f86f1
parent 29776 984a79b71cfe
permissions -rw-r--r--
8078660: Misleading recommendation from diamond finder. Summary: javac should recommend diamond usage if that could lead to a change in program behavior. Reviewed-by: mcimadamore

/*
 * @test /nodynamiccopyright/
 * @bug 8062373
 *
 * @summary  Test diamond + anonymous classes with non-denotable types
 * @author mcimadamore
 * @compile/fail/ref=Neg12.out Neg12.java -XDrawDiagnostics
 *
 */

 class Neg12 {
    static class Foo<X> {
        Foo(X x) {  }
    }

    static class DoubleFoo<X,Y> {
        DoubleFoo(X x,Y y) {  }
    }

    static class TripleFoo<X,Y,Z> {
        TripleFoo(X x,Y y,Z z) {  }
    }

    Foo<? extends Integer> fi = new Foo<>(1);
    Foo<?> fw = new Foo<>(fi) {}; // Error.
    Foo<?> fw1 = new Foo<>(fi); // OK.
    Foo<? extends Double> fd = new Foo<>(3.0);
    DoubleFoo<?,?> dw = new DoubleFoo<>(fi,fd) {}; // Error.
    DoubleFoo<?,?> dw1 = new DoubleFoo<>(fi,fd); // OK.
    Foo<String> fs = new Foo<>("one");
    TripleFoo<?,?,?> tw = new TripleFoo<>(fi,fd,fs) {}; // Error.
    TripleFoo<?,?,?> tw1 = new TripleFoo<>(fi,fd,fs); // OK.
 }