7157798: Add 6 test scenarios for testing inheritance of multiple same-name methods from mulitple interfaces

Mon, 21 May 2012 16:10:14 -0700

author
jjh
date
Mon, 21 May 2012 16:10:14 -0700
changeset 1266
f5dbd6895994
parent 1261
885806e74240
child 1267
f43aded513e7

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

test/tools/javac/generics/rawOverride/7157798/Test1.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/rawOverride/7157798/Test2.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/rawOverride/7157798/Test3.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/rawOverride/7157798/Test3.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/rawOverride/7157798/Test4.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/rawOverride/7157798/Test4.out file | annotate | diff | comparison | revisions
     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 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/generics/rawOverride/7157798/Test2.java	Mon May 21 16:10:14 2012 -0700
     2.3 @@ -0,0 +1,76 @@
     2.4 +/*
     2.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/**
    2.28 + * @test
    2.29 + * @bug      7062745 7157798
    2.30 + * @summary  Test inheritance of same-name methods from multiple interfaces
    2.31 +             when the methods have compatible parameter types and return types
    2.32 + * @compile  Test2.java
    2.33 + */
    2.34 +
    2.35 +import java.util.*;
    2.36 +
    2.37 +interface A { void m(Map map); }
    2.38 +interface B { void m(Map<Number, String> map); }
    2.39 +
    2.40 +interface AB extends A, B {} //paramter type: Map<Number, String>
    2.41 +
    2.42 +interface C<K, V> { List<V> getList(Map<K, V> map); }
    2.43 +interface D { ArrayList getList(Map map); }
    2.44 +
    2.45 +interface CD<K, V> extends C<K, V>, D {} //paramter type: Map<K, V>
    2.46 +
    2.47 +interface E<T> { T get(List<?> list); }
    2.48 +interface F<T> { T get(List list); }
    2.49 +
    2.50 +interface EF<T1, T2 extends T1> extends E<T1>, F<T2> {} //parameter type: List<?>
    2.51 +
    2.52 +class Test2 {
    2.53 +
    2.54 +    //compatible parameter types:
    2.55 +    void test(AB ab) {
    2.56 +        ab.m(new HashMap<Number, String>());
    2.57 +    }
    2.58 +
    2.59 +    //compatible parameter types and return types:
    2.60 +    void testRaw(CD cd) { //return type: ArrayList
    2.61 +        ArrayList al = cd.getList(new HashMap());
    2.62 +    }
    2.63 +
    2.64 +    <K, V> void testGeneric(CD<K, V> cd) { //return type: List<V>
    2.65 +        V v = cd.getList(new HashMap<K, V>()).get(0);
    2.66 +    }
    2.67 +
    2.68 +    void test(CD<Number, String> cd) { //return type: List<String>
    2.69 +        String s = cd.getList(new HashMap<Number, String>()).get(0);
    2.70 +    }
    2.71 +
    2.72 +    void test(EF<Number, Integer> ef) { //return type: Number
    2.73 +        Number n = ef.get(new ArrayList<Integer>());
    2.74 +    }
    2.75 +
    2.76 +    <T, U extends T> void testGeneric(EF<T, U> ef) { //return type: T
    2.77 +        T t = ef.get(new ArrayList<U>());
    2.78 +    }
    2.79 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/generics/rawOverride/7157798/Test3.java	Mon May 21 16:10:14 2012 -0700
     3.3 @@ -0,0 +1,37 @@
     3.4 +/**
     3.5 + * @test     /nodynamiccopyright/
     3.6 + * @bug      7062745 7157798
     3.7 + * @summary  Negative test of conflicting same-name methods inherited from multiple interfaces when return type not compatible
     3.8 + * @compile/fail/ref=Test3.out -Werror -Xlint:unchecked -XDrawDiagnostics Test3.java
     3.9 + */
    3.10 +
    3.11 +import java.util.List;
    3.12 +import java.io.Serializable;
    3.13 +
    3.14 +interface A { int m(); }
    3.15 +interface B { Integer m(); }
    3.16 +
    3.17 +interface AB extends A, B {} //error
    3.18 +
    3.19 +interface C { List<Integer> m(); }
    3.20 +interface D { List<Number> m(); }
    3.21 +
    3.22 +interface CD extends C, D {} //error
    3.23 +
    3.24 +interface E<T> { T m(); }
    3.25 +interface F<T> { T m(); }
    3.26 +interface G { Serializable m(); }
    3.27 +
    3.28 +interface BE extends B, E<Number> {} //ok, covariant return
    3.29 +
    3.30 +interface BE2<T> extends B, E<T> {} //error
    3.31 +
    3.32 +interface EF<T> extends E<T>, F<T> {} //ok
    3.33 +
    3.34 +interface EF2<U, V extends U> extends E<U>, F<V> {} //ok, covariant return
    3.35 +
    3.36 +interface EF3<U, V> extends E<U>, F<V> {} //error
    3.37 +
    3.38 +interface EG<T extends Number> extends E<T>, G {} //ok
    3.39 +
    3.40 +interface EFG<U extends Serializable, V extends Serializable> extends E<U>, F<V>, G {} //error
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/generics/rawOverride/7157798/Test3.out	Mon May 21 16:10:14 2012 -0700
     4.3 @@ -0,0 +1,6 @@
     4.4 +Test3.java:14:1: compiler.err.types.incompatible.diff.ret: B, A, m()
     4.5 +Test3.java:19:1: compiler.err.types.incompatible.diff.ret: D, C, m()
     4.6 +Test3.java:27:1: compiler.err.types.incompatible.diff.ret: E<T>, B, m()
     4.7 +Test3.java:33:1: compiler.err.types.incompatible.diff.ret: F<V>, E<U>, m()
     4.8 +Test3.java:37:1: compiler.err.types.incompatible.diff.ret: F<V>, E<U>, m()
     4.9 +5 errors
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/generics/rawOverride/7157798/Test4.java	Mon May 21 16:10:14 2012 -0700
     5.3 @@ -0,0 +1,29 @@
     5.4 +/**
     5.5 + * @test     /nodynamiccopyright/
     5.6 + * @bug      7062745 7157798
     5.7 + * @summary  Negative test of conflicting same-name methods inherited from multiple interfaces when parameter types not compatible
     5.8 + * @compile/fail/ref=Test4.out -Werror -Xlint:unchecked -XDrawDiagnostics Test4.java
     5.9 + */
    5.10 +
    5.11 +import java.util.Set;
    5.12 +import java.util.HashSet;
    5.13 +
    5.14 +interface A { void m(Set<Integer> s); }
    5.15 +interface B { void m(Set<String> s); }
    5.16 +interface C { void m(Set<?> s); }
    5.17 +
    5.18 +interface AB extends A, B {} //error
    5.19 +
    5.20 +interface AC extends A, C {} //error
    5.21 +
    5.22 +interface D<T> { void m(Set<T> s); }
    5.23 +
    5.24 +interface AD extends A, D<Integer> {} //OK
    5.25 +
    5.26 +interface AD2 extends A, D<Number> {} //error
    5.27 +
    5.28 +interface CD<T> extends C, D<T> {} //error
    5.29 +
    5.30 +interface E { <T> void m(Set<T> s); }
    5.31 +
    5.32 +interface DE<T> extends D<T>, E {} //error
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javac/generics/rawOverride/7157798/Test4.out	Mon May 21 16:10:14 2012 -0700
     6.3 @@ -0,0 +1,6 @@
     6.4 +Test4.java:15:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<java.lang.String>), B, m(java.util.Set<java.lang.Integer>), A
     6.5 +Test4.java:17:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<?>), C, m(java.util.Set<java.lang.Integer>), A
     6.6 +Test4.java:23:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<T>), D, m(java.util.Set<java.lang.Integer>), A
     6.7 +Test4.java:25:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<T>), D, m(java.util.Set<?>), C
     6.8 +Test4.java:29:1: compiler.err.name.clash.same.erasure.no.override: <T>m(java.util.Set<T>), E, m(java.util.Set<T>), D
     6.9 +5 errors

mercurial