# HG changeset patch # User jjh # Date 1337641814 25200 # Node ID f5dbd6895994a55e419cd998c6ec01c9ed485382 # Parent 885806e742400fd05859501751850b79f12abae5 7157798: Add 6 test scenarios for testing inheritance of multiple same-name methods from mulitple interfaces Reviewed-by: mcimadamore Contributed-by: sue.wei@oracle.com diff -r 885806e74240 -r f5dbd6895994 test/tools/javac/generics/rawOverride/7157798/Test1.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/rawOverride/7157798/Test1.java Mon May 21 16:10:14 2012 -0700 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 7062745 7157798 + * @summary Test inheritance of same-name methods from mulitple interfaces + when the methods have compatible return types + * @compile Test1.java + */ + +import java.util.*; + +interface A { List getList(); } +interface B { List getList(); } + +interface AB extends A, B {} //return type: List + +interface C { List getList(); } + +interface BC extends B, C {} //return type: List + +interface D { Number m(); } +interface E { Double m(); } + +interface DE extends D, E {} //return type: Double + +interface F { ArrayList getList(); } +interface G { Collection getList(); } + +interface AG extends A, G{}; //return type: List + +interface CF extends C, F {} //return type: ArrayList + +interface CG extends C, G {} //return type: List + +interface H { Iterable getList(); } + +interface CH extends C, H {} //return type: List + +interface CFGH extends C, F, G, H {} //return type: ArrayList + + +class Test1 { + + //raw and typed return types: + void test(AB ab) { + Number n = ab.getList().get(1); + } + + void test(BC bc) { + String s = bc.getList().get(1); + } + + void testRaw(BC bc) { + List list = bc.getList(); + } + + void testWildCard(BC bc) { + List list = bc.getList(); + } + + void testGeneric(BC bc) { + T t = bc.getList().get(1); + } + + //covariant return: + void test(DE de) { + Double d = de.m(); + } + + //mixed: + void test(AG ag) { + Number n = ag.getList().get(0); + } + + void test(CF cf) { + ArrayList list = cf.getList(); + } + + void test(CG cg) { + String s = cg.getList().get(0); + } + + void test(CH ch) { + String s = ch.getList().get(0); + } + + void test(CFGH cfgh) { + ArrayList list = cfgh.getList(); + } + + void testWildCard(CFGH cfgh) { + ArrayList list = cfgh.getList(); + } +} diff -r 885806e74240 -r f5dbd6895994 test/tools/javac/generics/rawOverride/7157798/Test2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/rawOverride/7157798/Test2.java Mon May 21 16:10:14 2012 -0700 @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 7062745 7157798 + * @summary Test inheritance of same-name methods from multiple interfaces + when the methods have compatible parameter types and return types + * @compile Test2.java + */ + +import java.util.*; + +interface A { void m(Map map); } +interface B { void m(Map map); } + +interface AB extends A, B {} //paramter type: Map + +interface C { List getList(Map map); } +interface D { ArrayList getList(Map map); } + +interface CD extends C, D {} //paramter type: Map + +interface E { T get(List list); } +interface F { T get(List list); } + +interface EF extends E, F {} //parameter type: List + +class Test2 { + + //compatible parameter types: + void test(AB ab) { + ab.m(new HashMap()); + } + + //compatible parameter types and return types: + void testRaw(CD cd) { //return type: ArrayList + ArrayList al = cd.getList(new HashMap()); + } + + void testGeneric(CD cd) { //return type: List + V v = cd.getList(new HashMap()).get(0); + } + + void test(CD cd) { //return type: List + String s = cd.getList(new HashMap()).get(0); + } + + void test(EF ef) { //return type: Number + Number n = ef.get(new ArrayList()); + } + + void testGeneric(EF ef) { //return type: T + T t = ef.get(new ArrayList()); + } +} diff -r 885806e74240 -r f5dbd6895994 test/tools/javac/generics/rawOverride/7157798/Test3.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/rawOverride/7157798/Test3.java Mon May 21 16:10:14 2012 -0700 @@ -0,0 +1,37 @@ +/** + * @test /nodynamiccopyright/ + * @bug 7062745 7157798 + * @summary Negative test of conflicting same-name methods inherited from multiple interfaces when return type not compatible + * @compile/fail/ref=Test3.out -Werror -Xlint:unchecked -XDrawDiagnostics Test3.java + */ + +import java.util.List; +import java.io.Serializable; + +interface A { int m(); } +interface B { Integer m(); } + +interface AB extends A, B {} //error + +interface C { List m(); } +interface D { List m(); } + +interface CD extends C, D {} //error + +interface E { T m(); } +interface F { T m(); } +interface G { Serializable m(); } + +interface BE extends B, E {} //ok, covariant return + +interface BE2 extends B, E {} //error + +interface EF extends E, F {} //ok + +interface EF2 extends E, F {} //ok, covariant return + +interface EF3 extends E, F {} //error + +interface EG extends E, G {} //ok + +interface EFG extends E, F, G {} //error diff -r 885806e74240 -r f5dbd6895994 test/tools/javac/generics/rawOverride/7157798/Test3.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/rawOverride/7157798/Test3.out Mon May 21 16:10:14 2012 -0700 @@ -0,0 +1,6 @@ +Test3.java:14:1: compiler.err.types.incompatible.diff.ret: B, A, m() +Test3.java:19:1: compiler.err.types.incompatible.diff.ret: D, C, m() +Test3.java:27:1: compiler.err.types.incompatible.diff.ret: E, B, m() +Test3.java:33:1: compiler.err.types.incompatible.diff.ret: F, E, m() +Test3.java:37:1: compiler.err.types.incompatible.diff.ret: F, E, m() +5 errors diff -r 885806e74240 -r f5dbd6895994 test/tools/javac/generics/rawOverride/7157798/Test4.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/rawOverride/7157798/Test4.java Mon May 21 16:10:14 2012 -0700 @@ -0,0 +1,29 @@ +/** + * @test /nodynamiccopyright/ + * @bug 7062745 7157798 + * @summary Negative test of conflicting same-name methods inherited from multiple interfaces when parameter types not compatible + * @compile/fail/ref=Test4.out -Werror -Xlint:unchecked -XDrawDiagnostics Test4.java + */ + +import java.util.Set; +import java.util.HashSet; + +interface A { void m(Set s); } +interface B { void m(Set s); } +interface C { void m(Set s); } + +interface AB extends A, B {} //error + +interface AC extends A, C {} //error + +interface D { void m(Set s); } + +interface AD extends A, D {} //OK + +interface AD2 extends A, D {} //error + +interface CD extends C, D {} //error + +interface E { void m(Set s); } + +interface DE extends D, E {} //error diff -r 885806e74240 -r f5dbd6895994 test/tools/javac/generics/rawOverride/7157798/Test4.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/rawOverride/7157798/Test4.out Mon May 21 16:10:14 2012 -0700 @@ -0,0 +1,6 @@ +Test4.java:15:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set), B, m(java.util.Set), A +Test4.java:17:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set), C, m(java.util.Set), A +Test4.java:23:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set), D, m(java.util.Set), A +Test4.java:25:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set), D, m(java.util.Set), C +Test4.java:29:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set), E, m(java.util.Set), D +5 errors