1 /* |
|
2 * @test /nodynamiccopyright/ |
|
3 * @bug 6840638 |
|
4 * |
|
5 * @summary Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond') |
|
6 * @author mcimadamore |
|
7 * @compile Pos03.java -source 1.7 |
|
8 * @run main Pos03 |
|
9 * |
|
10 */ |
|
11 |
|
12 public class Pos03<U> { |
|
13 |
|
14 class Foo<V> { |
|
15 Foo(V x) {} |
|
16 <Z> Foo(V x, Z z) {} |
|
17 } |
|
18 |
|
19 void testSimple() { |
|
20 Foo<Integer> f1 = new Foo<>(1); //new Foo<Integer> created |
|
21 Foo<? extends Integer> f2 = new Foo<>(1); //new Foo<Integer> created |
|
22 Foo<?> f3 = new Foo<>(1); //new Foo<Object> created |
|
23 Foo<? super Integer> f4 = new Foo<>(1); //new Foo<Object> created |
|
24 |
|
25 Foo<Integer> f5 = new Foo<>(1){}; //new Foo<Integer> created |
|
26 Foo<? extends Integer> f6 = new Foo<>(1){}; //new Foo<Integer> created |
|
27 Foo<?> f7 = new Foo<>(1){}; //new Foo<Object> created |
|
28 Foo<? super Integer> f8 = new Foo<>(1){}; //new Foo<Object> created |
|
29 |
|
30 Foo<Integer> f9 = new Foo<>(1, ""); //new Foo<Integer> created |
|
31 Foo<? extends Integer> f10 = new Foo<>(1, ""); //new Foo<Integer> created |
|
32 Foo<?> f11 = new Foo<>(1, ""); //new Foo<Object> created |
|
33 Foo<? super Integer> f12 = new Foo<>(1, ""); //new Foo<Object> created |
|
34 |
|
35 Foo<Integer> f13 = new Foo<>(1, ""){}; //new Foo<Integer> created |
|
36 Foo<? extends Integer> f14 = new Foo<>(1, ""){}; //new Foo<Integer> created |
|
37 Foo<?> f15 = new Foo<>(1, ""){}; //new Foo<Object> created |
|
38 Foo<? super Integer> f16 = new Foo<>(1, ""){}; //new Foo<Object> created |
|
39 } |
|
40 |
|
41 void testQualified_1() { |
|
42 Foo<Integer> f1 = new Pos03<U>.Foo<>(1); //new Foo<Integer> created |
|
43 Foo<? extends Integer> f2 = new Pos03<U>.Foo<>(1); //new Foo<Integer> created |
|
44 Foo<?> f3 = new Pos03<U>.Foo<>(1); //new Foo<Object> created |
|
45 Foo<? super Integer> f4 = new Pos03<U>.Foo<>(1); //new Foo<Object> created |
|
46 |
|
47 Foo<Integer> f5 = new Pos03<U>.Foo<>(1){}; //new Foo<Integer> created |
|
48 Foo<? extends Integer> f6 = new Pos03<U>.Foo<>(1){}; //new Foo<Integer> created |
|
49 Foo<?> f7 = new Pos03<U>.Foo<>(1){}; //new Foo<Object> created |
|
50 Foo<? super Integer> f8 = new Pos03<U>.Foo<>(1){}; //new Foo<Object> created |
|
51 |
|
52 Foo<Integer> f9 = new Pos03<U>.Foo<>(1, ""); //new Foo<Integer> created |
|
53 Foo<? extends Integer> f10 = new Pos03<U>.Foo<>(1, ""); //new Foo<Integer> created |
|
54 Foo<?> f11 = new Pos03<U>.Foo<>(1, ""); //new Foo<Object> created |
|
55 Foo<? super Integer> f12 = new Pos03<U>.Foo<>(1, ""); //new Foo<Object> created |
|
56 |
|
57 Foo<Integer> f13 = new Pos03<U>.Foo<>(1, ""){}; //new Foo<Integer> created |
|
58 Foo<? extends Integer> f14 = new Pos03<U>.Foo<>(1, ""){}; //new Foo<Integer> created |
|
59 Foo<?> f15 = new Pos03<U>.Foo<>(1, ""){}; //new Foo<Object> created |
|
60 Foo<? super Integer> f16 = new Pos03<U>.Foo<>(1, ""){}; //new Foo<Object> created |
|
61 } |
|
62 |
|
63 void testQualified_2(Pos03<U> p) { |
|
64 Foo<Integer> f1 = p.new Foo<>(1); //new Foo<Integer> created |
|
65 Foo<? extends Integer> f2 = p.new Foo<>(1); //new Foo<Integer> created |
|
66 Foo<?> f3 = p.new Foo<>(1); //new Foo<Object> created |
|
67 Foo<? super Integer> f4 = p.new Foo<>(1); //new Foo<Object> created |
|
68 |
|
69 Foo<Integer> f5 = p.new Foo<>(1){}; //new Foo<Integer> created |
|
70 Foo<? extends Integer> f6 = p.new Foo<>(1){}; //new Foo<Integer> created |
|
71 Foo<?> f7 = p.new Foo<>(1){}; //new Foo<Object> created |
|
72 Foo<? super Integer> f8 = p.new Foo<>(1){}; //new Foo<Object> created |
|
73 |
|
74 Foo<Integer> f9 = p.new Foo<>(1, ""); //new Foo<Integer> created |
|
75 Foo<? extends Integer> f10 = p.new Foo<>(1, ""); //new Foo<Integer> created |
|
76 Foo<?> f11 = p.new Foo<>(1, ""); //new Foo<Object> created |
|
77 Foo<? super Integer> f12 = p.new Foo<>(1, ""); //new Foo<Object> created |
|
78 |
|
79 Foo<Integer> f13 = p.new Foo<>(1, ""){}; //new Foo<Integer> created |
|
80 Foo<? extends Integer> f14 = p.new Foo<>(1, ""){}; //new Foo<Integer> created |
|
81 Foo<?> f15 = p.new Foo<>(1, ""){}; //new Foo<Object> created |
|
82 Foo<? super Integer> f16 = p.new Foo<>(1, ""){}; //new Foo<Object> created |
|
83 } |
|
84 |
|
85 public static void main(String[] args) { |
|
86 Pos03<String> p3 = new Pos03<>(); |
|
87 p3.testSimple(); |
|
88 p3.testQualified_1(); |
|
89 p3.testQualified_2(p3); |
|
90 } |
|
91 } |
|