test/tools/javac/generics/diamond/pos/Pos03.java

changeset 537
9d9d08922405
child 543
97b6fa97b8dd
equal deleted inserted replaced
536:396b117c1743 537:9d9d08922405
1 /*
2 * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24 /*
25 * @test
26 * @bug 6939620
27 *
28 * @summary Switch to 'complex' diamond inference scheme
29 * @author mcimadamore
30 * @compile Pos03.java
31 * @run main Pos03
32 *
33 */
34
35 public class Pos03<U> {
36
37 class Foo<V> {
38 Foo(V x) {}
39 <Z> Foo(V x, Z z) {}
40 }
41
42 void testSimple() {
43 Foo<Integer> f1 = new Foo<>(1);
44 Foo<? extends Integer> f2 = new Foo<>(1);
45 Foo<?> f3 = new Foo<>(1);
46 Foo<? super Integer> f4 = new Foo<>(1);
47
48 Foo<Integer> f5 = new Foo<>(1){};
49 Foo<? extends Integer> f6 = new Foo<>(1){};
50 Foo<?> f7 = new Foo<>(1){};
51 Foo<? super Integer> f8 = new Foo<>(1){};
52
53 Foo<Integer> f9 = new Foo<>(1, "");
54 Foo<? extends Integer> f10 = new Foo<>(1, "");
55 Foo<?> f11 = new Foo<>(1, "");
56 Foo<? super Integer> f12 = new Foo<>(1, "");
57
58 Foo<Integer> f13 = new Foo<>(1, ""){};
59 Foo<? extends Integer> f14 = new Foo<>(1, ""){};
60 Foo<?> f15 = new Foo<>(1, ""){};
61 Foo<? super Integer> f16 = new Foo<>(1, ""){};
62 }
63
64 void testQualified_1() {
65 Foo<Integer> f1 = new Pos03<U>.Foo<>(1);
66 Foo<? extends Integer> f2 = new Pos03<U>.Foo<>(1);
67 Foo<?> f3 = new Pos03<U>.Foo<>(1);
68 Foo<? super Integer> f4 = new Pos03<U>.Foo<>(1);
69
70 Foo<Integer> f5 = new Pos03<U>.Foo<>(1){};
71 Foo<? extends Integer> f6 = new Pos03<U>.Foo<>(1){};
72 Foo<?> f7 = new Pos03<U>.Foo<>(1){};
73 Foo<? super Integer> f8 = new Pos03<U>.Foo<>(1){};
74
75 Foo<Integer> f9 = new Pos03<U>.Foo<>(1, "");
76 Foo<? extends Integer> f10 = new Pos03<U>.Foo<>(1, "");
77 Foo<?> f11 = new Pos03<U>.Foo<>(1, "");
78 Foo<? super Integer> f12 = new Pos03<U>.Foo<>(1, "");
79
80 Foo<Integer> f13 = new Pos03<U>.Foo<>(1, ""){};
81 Foo<? extends Integer> f14 = new Pos03<U>.Foo<>(1, ""){};
82 Foo<?> f15 = new Pos03<U>.Foo<>(1, ""){};
83 Foo<? super Integer> f16 = new Pos03<U>.Foo<>(1, ""){};
84 }
85
86 void testQualified_2(Pos03<U> p) {
87 Foo<Integer> f1 = p.new Foo<>(1);
88 Foo<? extends Integer> f2 = p.new Foo<>(1);
89 Foo<?> f3 = p.new Foo<>(1);
90 Foo<? super Integer> f4 = p.new Foo<>(1);
91
92 Foo<Integer> f5 = p.new Foo<>(1){};
93 Foo<? extends Integer> f6 = p.new Foo<>(1){};
94 Foo<?> f7 = p.new Foo<>(1){};
95 Foo<? super Integer> f8 = p.new Foo<>(1){};
96
97 Foo<Integer> f9 = p.new Foo<>(1, "");
98 Foo<? extends Integer> f10 = p.new Foo<>(1, "");
99 Foo<?> f11 = p.new Foo<>(1, "");
100 Foo<? super Integer> f12 = p.new Foo<>(1, "");
101
102 Foo<Integer> f13 = p.new Foo<>(1, ""){};
103 Foo<? extends Integer> f14 = p.new Foo<>(1, ""){};
104 Foo<?> f15 = p.new Foo<>(1, ""){};
105 Foo<? super Integer> f16 = p.new Foo<>(1, ""){};
106 }
107
108 public static void main(String[] args) {
109 Pos03<String> p3 = new Pos03<>();
110 p3.testSimple();
111 p3.testQualified_1();
112 p3.testQualified_2(p3);
113 }
114 }

mercurial