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 multiple interfaces
28              when the methods have compatible parameter types and return types
29  * @compile  Test2.java
30  */
31 
32 import java.util.*;
33 
m(Map map)34 interface A { void m(Map map); }
m(Map<Number, String> map)35 interface B { void m(Map<Number, String> map); }
36 
37 interface AB extends A, B {} //paramter type: Map<Number, String>
38 
getList(Map<K, V> map)39 interface C<K, V> { List<V> getList(Map<K, V> map); }
getList(Map map)40 interface D { ArrayList getList(Map map); }
41 
42 interface CD<K, V> extends C<K, V>, D {} //paramter type: Map<K, V>
43 
get(List<?> list)44 interface E<T> { T get(List<?> list); }
get(List list)45 interface F<T> { T get(List list); }
46 
47 interface EF<T1, T2 extends T1> extends E<T1>, F<T2> {} //parameter type: List<?>
48 
49 class Test2 {
50 
51     //compatible parameter types:
test(AB ab)52     void test(AB ab) {
53         ab.m(new HashMap<Number, String>());
54     }
55 
56     //compatible parameter types and return types:
testRaw(CD cd)57     void testRaw(CD cd) { //return type: ArrayList
58         ArrayList al = cd.getList(new HashMap());
59     }
60 
testGeneric(CD<K, V> cd)61     <K, V> void testGeneric(CD<K, V> cd) { //return type: List<V>
62         V v = cd.getList(new HashMap<K, V>()).get(0);
63     }
64 
test(CD<Number, String> cd)65     void test(CD<Number, String> cd) { //return type: List<String>
66         String s = cd.getList(new HashMap<Number, String>()).get(0);
67     }
68 
test(EF<Number, Integer> ef)69     void test(EF<Number, Integer> ef) { //return type: Number
70         Number n = ef.get(new ArrayList<Integer>());
71     }
72 
testGeneric(EF<T, U> ef)73     <T, U extends T> void testGeneric(EF<T, U> ef) { //return type: T
74         T t = ef.get(new ArrayList<U>());
75     }
76 }
77