T6939780.java revision 2868:816bd88d33a8
1/*
2 * @test /nodynamiccopyright/
3 * @bug 6939780 7020044 8009459 8021338 8064365 8062373
4 *
5 * @summary  add a warning to detect diamond sites (including anonymous class instance creation at source >= 9)
6 * @author mcimadamore
7 * @compile/ref=T6939780_7.out -Xlint:-options -source 7 T6939780.java -XDrawDiagnostics -XDfind=diamond
8 * @compile/ref=T6939780_8.out -Xlint:-options -source 8 T6939780.java -XDrawDiagnostics -XDfind=diamond
9 * @compile/ref=T6939780_9.out -Xlint:-options -source 9 T6939780.java -XDrawDiagnostics -XDfind=diamond
10 *
11 */
12
13class T6939780 {
14
15    static class Foo<X extends Number> {
16        Foo() {}
17        Foo(X x) {}
18    }
19
20    void testAssign() {
21        Foo<Number> f1 = new Foo<Number>(1);
22        Foo<?> f2 = new Foo<Number>();
23        Foo<?> f3 = new Foo<Integer>();
24        Foo<Number> f4 = new Foo<Number>(1) {};
25        Foo<?> f5 = new Foo<Number>() {};
26        Foo<?> f6 = new Foo<Integer>() {};
27    }
28
29    void testMethod() {
30        gn(new Foo<Number>(1));
31        gw(new Foo<Number>());
32        gw(new Foo<Integer>());
33        gn(new Foo<Number>(1) {});
34        gw(new Foo<Number>() {});
35        gw(new Foo<Integer>() {});
36    }
37
38    void gw(Foo<?> fw) { }
39    void gn(Foo<Number> fn) { }
40
41    static class Foo2<X> {
42        X copy(X t) {
43            return t;
44        }
45    }
46
47    void testReciever() {
48        Number s = new Foo2<Number>().copy(0);
49    }
50
51}
52