1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/generics/rawOverride/7157798/Test1.java Mon May 21 16:10:14 2012 -0700 1.3 @@ -0,0 +1,116 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/** 1.28 + * @test 1.29 + * @bug 7062745 7157798 1.30 + * @summary Test inheritance of same-name methods from mulitple interfaces 1.31 + when the methods have compatible return types 1.32 + * @compile Test1.java 1.33 + */ 1.34 + 1.35 +import java.util.*; 1.36 + 1.37 +interface A { List<Number> getList(); } 1.38 +interface B { List getList(); } 1.39 + 1.40 +interface AB extends A, B {} //return type: List<Number> 1.41 + 1.42 +interface C<T> { List<T> getList(); } 1.43 + 1.44 +interface BC<T> extends B, C<T> {} //return type: List<T> 1.45 + 1.46 +interface D { Number m(); } 1.47 +interface E { Double m(); } 1.48 + 1.49 +interface DE extends D, E {} //return type: Double 1.50 + 1.51 +interface F { ArrayList getList(); } 1.52 +interface G { Collection getList(); } 1.53 + 1.54 +interface AG extends A, G{}; //return type: List<Number> 1.55 + 1.56 +interface CF<T> extends C<T>, F {} //return type: ArrayList 1.57 + 1.58 +interface CG<T> extends C<T>, G {} //return type: List<T> 1.59 + 1.60 +interface H<T> { Iterable<T> getList(); } 1.61 + 1.62 +interface CH<T> extends C<T>, H<T> {} //return type: List<T> 1.63 + 1.64 +interface CFGH<T> extends C<T>, F, G, H<T> {} //return type: ArrayList 1.65 + 1.66 + 1.67 +class Test1 { 1.68 + 1.69 + //raw and typed return types: 1.70 + void test(AB ab) { 1.71 + Number n = ab.getList().get(1); 1.72 + } 1.73 + 1.74 + void test(BC<String> bc) { 1.75 + String s = bc.getList().get(1); 1.76 + } 1.77 + 1.78 + void testRaw(BC bc) { 1.79 + List list = bc.getList(); 1.80 + } 1.81 + 1.82 + void testWildCard(BC<?> bc) { 1.83 + List<?> list = bc.getList(); 1.84 + } 1.85 + 1.86 + <T> void testGeneric(BC<T> bc) { 1.87 + T t = bc.getList().get(1); 1.88 + } 1.89 + 1.90 + //covariant return: 1.91 + void test(DE de) { 1.92 + Double d = de.m(); 1.93 + } 1.94 + 1.95 + //mixed: 1.96 + void test(AG ag) { 1.97 + Number n = ag.getList().get(0); 1.98 + } 1.99 + 1.100 + void test(CF<Integer> cf) { 1.101 + ArrayList list = cf.getList(); 1.102 + } 1.103 + 1.104 + void test(CG<String> cg) { 1.105 + String s = cg.getList().get(0); 1.106 + } 1.107 + 1.108 + void test(CH<String> ch) { 1.109 + String s = ch.getList().get(0); 1.110 + } 1.111 + 1.112 + void test(CFGH<Double> cfgh) { 1.113 + ArrayList list = cfgh.getList(); 1.114 + } 1.115 + 1.116 + void testWildCard(CFGH<?> cfgh) { 1.117 + ArrayList list = cfgh.getList(); 1.118 + } 1.119 +}