test/tools/javac/generics/SuperTypeargs.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

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

mercurial