test/tools/javac/generics/SuperTypeargs.java

Mon, 26 Oct 2015 13:23:30 -0700

author
asaha
date
Mon, 26 Oct 2015 13:23:30 -0700
changeset 2999
683b3e7e05a7
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u76-b00 for changeset 10ffafaf5340

duke@1 1 /*
ohair@554 2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
ohair@554 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 20 * or visit www.oracle.com if you need additional information or have any
ohair@554 21 * questions.
duke@1 22 */
duke@1 23
duke@1 24 /*
duke@1 25 * @test
duke@1 26 * @bug 4906605
duke@1 27 * @summary compilation error for super.<T,E>f() and ClassName.super.<T,E>f()
duke@1 28 * @author gafter
duke@1 29 *
darcy@289 30 * @compile SuperTypeargs.java
duke@1 31 */
duke@1 32
duke@1 33 package superTypeargs;
duke@1 34
duke@1 35 import java.util.*;
duke@1 36
duke@1 37 class A {
duke@1 38
duke@1 39 public void show() {
duke@1 40 System.out.println("I am being called from class A");
duke@1 41 }
duke@1 42 public String toString() {
duke@1 43 show();
duke@1 44 return "";
duke@1 45 }
duke@1 46 }
duke@1 47
duke@1 48 class B {
duke@1 49 public void show() {
duke@1 50 System.out.println("I am being called from class B");
duke@1 51 }
duke@1 52 public String toString() {
duke@1 53 show();
duke@1 54 return "";
duke@1 55 }
duke@1 56 }
duke@1 57
duke@1 58 class Test1<T,E> {
duke@1 59
duke@1 60 public static <T,E> void check1(T val1, E val2) {
duke@1 61 val1.toString();
duke@1 62 val2.toString();
duke@1 63 System.out.println("Static check1 method being invoked from class Test1");
duke@1 64 }
duke@1 65
duke@1 66 public <T,E> Test1(){
duke@1 67 System.out.println("The Default Test1 constructor is being called");
duke@1 68 }
duke@1 69 public <T,E> Test1(T val1, E val2) {
duke@1 70 System.out.println("The parameter Test1 constructor is being called");
duke@1 71 }
duke@1 72 public <T,E> int check2(T val1, E val2) {
duke@1 73 val1.toString();
duke@1 74 val2.toString();
duke@1 75 System.out.println("Instance method check2 being invoked from class Test1");
duke@1 76 return 1;
duke@1 77 }
duke@1 78
duke@1 79 }
duke@1 80
duke@1 81 class Test2<T,E> extends Test1<T,E> {
duke@1 82
duke@1 83 public static <T,E> void check1(T val1, E val2) {
duke@1 84 val1.toString();
duke@1 85 val2.toString();
duke@1 86 System.out.println("Static check1 method being invoked from class Test2");
duke@1 87 }
duke@1 88
duke@1 89 public Test2() {
duke@1 90 <T,E>super();
duke@1 91 System.out.println("The Default Test2 constructor is being called");
duke@1 92 }
duke@1 93 public <T,E> Test2(T val1, E val2) {
duke@1 94 <T,E>super(val1,val2);
duke@1 95 System.out.println("The parameter Test2 constructor is being called");
duke@1 96 }
duke@1 97 public <T,E> int check2(T val1, E val2) {
duke@1 98 val1.toString();
duke@1 99 val2.toString();
duke@1 100 System.out.println("Instance method check2 being invoked from class Test2");
duke@1 101 return 1;
duke@1 102 }
duke@1 103
duke@1 104 public <T,E> int check3(T val1, E val2) {
duke@1 105 System.out.println("Instance method check3 being invoked from class Test2");
duke@1 106 super.<T,E>check2(val1,val2);
duke@1 107 /*
duke@1 108 ParametericMethodsTest13.java:66: <identifier> expected
duke@1 109 super . <T,E> check2(val1,val2);
duke@1 110 ^
duke@1 111 ParametericMethodsTest13.java:66: not a statement
duke@1 112 super . <T,E> check2(val1,val2);
duke@1 113 ^
duke@1 114 2 errors
duke@1 115 */
duke@1 116 this.<T,E>check2(val1,val2);
duke@1 117 Test2.super.<T,E>check2(val1,val2);
duke@1 118 return 1;
duke@1 119 }
duke@1 120
duke@1 121 /*
duke@1 122 ParametericMethodsTest14.java:130: check4(A,B) in Test2<A,B> cannot be applied to <A,B>(A,B)
duke@1 123 tRef.<A,B>check4(new A(), new B());
duke@1 124 ^
duke@1 125 1 error
duke@1 126 */
duke@1 127 public int check4(T val1, E val2) {
duke@1 128 val1.toString();
duke@1 129 val2.toString();
duke@1 130 System.out.println("Instance method check2 being invoked from class Test2");
duke@1 131 return 1;
duke@1 132 }
duke@1 133
duke@1 134 }
duke@1 135
duke@1 136 class ParametericMethodsTest14 {
duke@1 137
duke@1 138 public void assertion1() {
duke@1 139 Test2.<A,B>check1(new A(), new B());
duke@1 140 Test1.<A,B>check1(new A(), new B());
duke@1 141 System.out.println("assertion1 passed");
duke@1 142 }
duke@1 143 public void assertion2() {
duke@1 144 Test2<A,B> tRef = new Test2<A,B>();
duke@1 145 tRef.<A,B>check1(new A(), new B());
duke@1 146 tRef.<A,B>check2(new A(), new B());
duke@1 147 Test1<A,B> tRef1 = tRef;
duke@1 148 tRef1.<A,B>check1(new A(), new B());
duke@1 149 System.out.println("assertion2 passed");
duke@1 150 }
duke@1 151 public void assertion3() {
duke@1 152 Test2<A,B> tRef = new Test2<A,B>();
duke@1 153 tRef.<A,B>check3(new A(), new B());
duke@1 154 }
duke@1 155 public void assertion4() {
duke@1 156 Test2<A,B> tRef = new Test2<A,B>(new A(), new B());
duke@1 157 tRef.<A,B>check3(new A(), new B());
duke@1 158 }
duke@1 159
duke@1 160 public static void main(String args[]) {
duke@1 161 ParametericMethodsTest14 tRef = new ParametericMethodsTest14();
duke@1 162 tRef.assertion1();
duke@1 163 tRef.assertion2();
duke@1 164 tRef.assertion3();
duke@1 165 tRef.assertion4();
duke@1 166 }
duke@1 167
duke@1 168 }

mercurial