test/tools/javac/generics/SuperTypeargs.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/generics/SuperTypeargs.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,168 @@
     1.4 +/*
     1.5 + * Copyright (c) 2004, 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 4906605
    1.30 + * @summary compilation error for super.<T,E>f() and ClassName.super.<T,E>f()
    1.31 + * @author gafter
    1.32 + *
    1.33 + * @compile  SuperTypeargs.java
    1.34 + */
    1.35 +
    1.36 +package superTypeargs;
    1.37 +
    1.38 +import java.util.*;
    1.39 +
    1.40 +class A {
    1.41 +
    1.42 +    public void show() {
    1.43 +        System.out.println("I am being called from class A");
    1.44 +    }
    1.45 +    public String toString() {
    1.46 +        show();
    1.47 +        return "";
    1.48 +    }
    1.49 +}
    1.50 +
    1.51 +class B {
    1.52 +    public void show() {
    1.53 +        System.out.println("I am being called from class B");
    1.54 +    }
    1.55 +    public String toString() {
    1.56 +        show();
    1.57 +        return "";
    1.58 +    }
    1.59 +}
    1.60 +
    1.61 +class Test1<T,E> {
    1.62 +
    1.63 +    public static <T,E> void check1(T val1, E val2) {
    1.64 +        val1.toString();
    1.65 +        val2.toString();
    1.66 +        System.out.println("Static check1 method being invoked from class Test1");
    1.67 +    }
    1.68 +
    1.69 +    public <T,E> Test1(){
    1.70 +        System.out.println("The Default Test1 constructor is being called");
    1.71 +    }
    1.72 +    public <T,E> Test1(T val1, E val2) {
    1.73 +        System.out.println("The parameter Test1 constructor is being called");
    1.74 +    }
    1.75 +    public <T,E> int check2(T val1, E val2) {
    1.76 +        val1.toString();
    1.77 +        val2.toString();
    1.78 +        System.out.println("Instance method check2 being invoked from class Test1");
    1.79 +        return 1;
    1.80 +    }
    1.81 +
    1.82 +}
    1.83 +
    1.84 +class Test2<T,E> extends Test1<T,E> {
    1.85 +
    1.86 +    public static <T,E> void check1(T val1, E val2) {
    1.87 +        val1.toString();
    1.88 +        val2.toString();
    1.89 +        System.out.println("Static check1 method being invoked from class Test2");
    1.90 +    }
    1.91 +
    1.92 +    public Test2() {
    1.93 +        <T,E>super();
    1.94 +        System.out.println("The Default Test2 constructor is being called");
    1.95 +    }
    1.96 +    public <T,E> Test2(T val1, E val2) {
    1.97 +        <T,E>super(val1,val2);
    1.98 +        System.out.println("The parameter Test2 constructor is being called");
    1.99 +    }
   1.100 +    public <T,E> int check2(T val1, E val2) {
   1.101 +        val1.toString();
   1.102 +        val2.toString();
   1.103 +        System.out.println("Instance method check2 being invoked from class Test2");
   1.104 +        return 1;
   1.105 +    }
   1.106 +
   1.107 +    public <T,E> int check3(T val1, E val2) {
   1.108 +        System.out.println("Instance method check3 being invoked from class Test2");
   1.109 +        super.<T,E>check2(val1,val2);
   1.110 +        /*
   1.111 +             ParametericMethodsTest13.java:66: <identifier> expected
   1.112 +             super . <T,E> check2(val1,val2);
   1.113 +             ^
   1.114 +             ParametericMethodsTest13.java:66: not a statement
   1.115 +             super . <T,E> check2(val1,val2);
   1.116 +                   ^
   1.117 +             2 errors
   1.118 +        */
   1.119 +        this.<T,E>check2(val1,val2);
   1.120 +        Test2.super.<T,E>check2(val1,val2);
   1.121 +        return 1;
   1.122 +    }
   1.123 +
   1.124 +    /*
   1.125 +      ParametericMethodsTest14.java:130: check4(A,B) in Test2<A,B> cannot be applied to <A,B>(A,B)
   1.126 +      tRef.<A,B>check4(new A(), new B());
   1.127 +            ^
   1.128 +      1 error
   1.129 +    */
   1.130 +    public int check4(T val1, E val2) {
   1.131 +        val1.toString();
   1.132 +        val2.toString();
   1.133 +        System.out.println("Instance method check2 being invoked from class Test2");
   1.134 +        return 1;
   1.135 +    }
   1.136 +
   1.137 +}
   1.138 +
   1.139 +class ParametericMethodsTest14 {
   1.140 +
   1.141 +    public void assertion1() {
   1.142 +        Test2.<A,B>check1(new A(), new B());
   1.143 +        Test1.<A,B>check1(new A(), new B());
   1.144 +        System.out.println("assertion1 passed");
   1.145 +    }
   1.146 +    public void assertion2() {
   1.147 +        Test2<A,B> tRef = new Test2<A,B>();
   1.148 +        tRef.<A,B>check1(new A(), new B());
   1.149 +        tRef.<A,B>check2(new A(), new B());
   1.150 +        Test1<A,B> tRef1 = tRef;
   1.151 +        tRef1.<A,B>check1(new A(), new B());
   1.152 +        System.out.println("assertion2 passed");
   1.153 +    }
   1.154 +    public void assertion3() {
   1.155 +        Test2<A,B> tRef = new Test2<A,B>();
   1.156 +        tRef.<A,B>check3(new A(), new B());
   1.157 +    }
   1.158 +    public void assertion4() {
   1.159 +        Test2<A,B> tRef = new Test2<A,B>(new A(), new B());
   1.160 +        tRef.<A,B>check3(new A(), new B());
   1.161 +    }
   1.162 +
   1.163 +    public static void main(String args[]) {
   1.164 +        ParametericMethodsTest14 tRef = new ParametericMethodsTest14();
   1.165 +        tRef.assertion1();
   1.166 +        tRef.assertion2();
   1.167 +        tRef.assertion3();
   1.168 +        tRef.assertion4();
   1.169 +    }
   1.170 +
   1.171 +}

mercurial