|
1 /* |
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /** |
|
25 * @test |
|
26 * @bug 7062745 7157798 |
|
27 * @summary Test inheritance of same-name methods from mulitple interfaces |
|
28 when the methods have compatible return types |
|
29 * @compile Test1.java |
|
30 */ |
|
31 |
|
32 import java.util.*; |
|
33 |
|
34 interface A { List<Number> getList(); } |
|
35 interface B { List getList(); } |
|
36 |
|
37 interface AB extends A, B {} //return type: List<Number> |
|
38 |
|
39 interface C<T> { List<T> getList(); } |
|
40 |
|
41 interface BC<T> extends B, C<T> {} //return type: List<T> |
|
42 |
|
43 interface D { Number m(); } |
|
44 interface E { Double m(); } |
|
45 |
|
46 interface DE extends D, E {} //return type: Double |
|
47 |
|
48 interface F { ArrayList getList(); } |
|
49 interface G { Collection getList(); } |
|
50 |
|
51 interface AG extends A, G{}; //return type: List<Number> |
|
52 |
|
53 interface CF<T> extends C<T>, F {} //return type: ArrayList |
|
54 |
|
55 interface CG<T> extends C<T>, G {} //return type: List<T> |
|
56 |
|
57 interface H<T> { Iterable<T> getList(); } |
|
58 |
|
59 interface CH<T> extends C<T>, H<T> {} //return type: List<T> |
|
60 |
|
61 interface CFGH<T> extends C<T>, F, G, H<T> {} //return type: ArrayList |
|
62 |
|
63 |
|
64 class Test1 { |
|
65 |
|
66 //raw and typed return types: |
|
67 void test(AB ab) { |
|
68 Number n = ab.getList().get(1); |
|
69 } |
|
70 |
|
71 void test(BC<String> bc) { |
|
72 String s = bc.getList().get(1); |
|
73 } |
|
74 |
|
75 void testRaw(BC bc) { |
|
76 List list = bc.getList(); |
|
77 } |
|
78 |
|
79 void testWildCard(BC<?> bc) { |
|
80 List<?> list = bc.getList(); |
|
81 } |
|
82 |
|
83 <T> void testGeneric(BC<T> bc) { |
|
84 T t = bc.getList().get(1); |
|
85 } |
|
86 |
|
87 //covariant return: |
|
88 void test(DE de) { |
|
89 Double d = de.m(); |
|
90 } |
|
91 |
|
92 //mixed: |
|
93 void test(AG ag) { |
|
94 Number n = ag.getList().get(0); |
|
95 } |
|
96 |
|
97 void test(CF<Integer> cf) { |
|
98 ArrayList list = cf.getList(); |
|
99 } |
|
100 |
|
101 void test(CG<String> cg) { |
|
102 String s = cg.getList().get(0); |
|
103 } |
|
104 |
|
105 void test(CH<String> ch) { |
|
106 String s = ch.getList().get(0); |
|
107 } |
|
108 |
|
109 void test(CFGH<Double> cfgh) { |
|
110 ArrayList list = cfgh.getList(); |
|
111 } |
|
112 |
|
113 void testWildCard(CFGH<?> cfgh) { |
|
114 ArrayList list = cfgh.getList(); |
|
115 } |
|
116 } |