Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/reflect/Generics/StringsAndBounds.java
38828 views
/*1* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 5015676 4987888 499746426* @summary Testing upper bounds and availability of toString methods27* @author Joseph D. Darcy28*/2930import java.lang.reflect.*;31import java.util.List;32import java.util.Collection;3334class A<T> {35class B<U> {}36}3738class Test<T> {39static class Inner1<U> {40void bar(U[] array1) { return;}41}4243class Inner2<V> {44List<?> foo2(List<? extends V> t) {45return null;46}47}4849static <S extends Object & Comparable<? super S> > S max(Collection<? extends S> coll) {50return null;51}5253List<? extends T> foo(List<? super T> t) {54return null;55}56}5758public class StringsAndBounds {59public void f(A<String>.B<Integer> x) {60}6162public <T> void g(T a) {return ;}6364static void scanner(Class clazz) {65System.out.println("\n\nScanning " + clazz.getName());6667for(Class c: clazz.getDeclaredClasses()) {68scanner(c);69}7071for(Method m: clazz.getDeclaredMethods()) {72System.out.println("\nMethod:\t" + m.toString()); // Need toGenericString?73System.out.println("\tReturn Type: " + m.getGenericReturnType().toString() );74for(Type p: m.getGenericParameterTypes()) {75if (p instanceof WildcardType) { // Check upper bounds76Type[] upperBounds = ((WildcardType)p).getUpperBounds();77if (upperBounds.length < 1 ||78upperBounds[0] == null)79throw new RuntimeException("Malformed upper bounds: " + p);8081}8283System.out.println("\tParameter: " + p.toString());84}85}86}8788public static void main(String[] argv) throws Exception {89scanner(StringsAndBounds.class);90scanner(A.B.class);91scanner(Test.class);92}93}949596