1 /*
   2  * Copyright 2004 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4906605
  27  * @summary compilation error for super.<T,E>f() and ClassName.super.<T,E>f()
  28  * @author gafter
  29  *
  30  * @compile -source 1.5 SuperTypeargs.java
  31  */
  32 
  33 package superTypeargs;
  34 
  35 import java.util.*;
  36 
  37 class A {
  38 
  39     public void show() {
  40         System.out.println("I am being called from class A");
  41     }
  42     public String toString() {
  43         show();
  44         return "";
  45     }
  46 }
  47 
  48 class B {
  49     public void show() {
  50         System.out.println("I am being called from class B");
  51     }
  52     public String toString() {
  53         show();
  54         return "";
  55     }
  56 }
  57 
  58 class Test1<T,E> {
  59 
  60     public static <T,E> void check1(T val1, E val2) {
  61         val1.toString();
  62         val2.toString();
  63         System.out.println("Static check1 method being invoked from class Test1");
  64     }
  65 
  66     public <T,E> Test1(){
  67         System.out.println("The Default Test1 constructor is being called");
  68     }
  69     public <T,E> Test1(T val1, E val2) {
  70         System.out.println("The parameter Test1 constructor is being called");
  71     }
  72     public <T,E> int check2(T val1, E val2) {
  73         val1.toString();
  74         val2.toString();
  75         System.out.println("Instance method check2 being invoked from class Test1");
  76         return 1;
  77     }
  78 
  79 }
  80 
  81 class Test2<T,E> extends Test1<T,E> {
  82 
  83     public static <T,E> void check1(T val1, E val2) {
  84         val1.toString();
  85         val2.toString();
  86         System.out.println("Static check1 method being invoked from class Test2");
  87     }
  88 
  89     public Test2() {
  90         <T,E>super();
  91         System.out.println("The Default Test2 constructor is being called");
  92     }
  93     public <T,E> Test2(T val1, E val2) {
  94         <T,E>super(val1,val2);
  95         System.out.println("The parameter Test2 constructor is being called");
  96     }
  97     public <T,E> int check2(T val1, E val2) {
  98         val1.toString();
  99         val2.toString();
 100         System.out.println("Instance method check2 being invoked from class Test2");
 101         return 1;
 102     }
 103 
 104     public <T,E> int check3(T val1, E val2) {
 105         System.out.println("Instance method check3 being invoked from class Test2");
 106         super.<T,E>check2(val1,val2);
 107         /*
 108              ParametericMethodsTest13.java:66: <identifier> expected
 109              super . <T,E> check2(val1,val2);
 110              ^
 111              ParametericMethodsTest13.java:66: not a statement
 112              super . <T,E> check2(val1,val2);
 113                    ^
 114              2 errors
 115         */
 116         this.<T,E>check2(val1,val2);
 117         Test2.super.<T,E>check2(val1,val2);
 118         return 1;
 119     }
 120 
 121     /*
 122       ParametericMethodsTest14.java:130: check4(A,B) in Test2<A,B> cannot be applied to <A,B>(A,B)
 123       tRef.<A,B>check4(new A(), new B());
 124             ^
 125       1 error
 126     */
 127     public int check4(T val1, E val2) {
 128         val1.toString();
 129         val2.toString();
 130         System.out.println("Instance method check2 being invoked from class Test2");
 131         return 1;
 132     }
 133 
 134 }
 135 
 136 class ParametericMethodsTest14 {
 137 
 138     public void assertion1() {
 139         Test2.<A,B>check1(new A(), new B());
 140         Test1.<A,B>check1(new A(), new B());
 141         System.out.println("assertion1 passed");
 142     }
 143     public void assertion2() {
 144         Test2<A,B> tRef = new Test2<A,B>();
 145         tRef.<A,B>check1(new A(), new B());
 146         tRef.<A,B>check2(new A(), new B());
 147         Test1<A,B> tRef1 = tRef;
 148         tRef1.<A,B>check1(new A(), new B());
 149         System.out.println("assertion2 passed");
 150     }
 151     public void assertion3() {
 152         Test2<A,B> tRef = new Test2<A,B>();
 153         tRef.<A,B>check3(new A(), new B());
 154     }
 155     public void assertion4() {
 156         Test2<A,B> tRef = new Test2<A,B>(new A(), new B());
 157         tRef.<A,B>check3(new A(), new B());
 158     }
 159 
 160     public static void main(String args[]) {
 161         ParametericMethodsTest14 tRef = new ParametericMethodsTest14();
 162         tRef.assertion1();
 163         tRef.assertion2();
 164         tRef.assertion3();
 165         tRef.assertion4();
 166     }
 167 
 168 }