blob: 36406bb49eae5357206a0dbe1c960dcc056a2dd1 [file] [log] [blame]
Yohann Roussel804b7582017-07-26 15:51:17 +02001// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4package minifygeneric;
5
6import java.lang.reflect.Field;
7import java.lang.reflect.ParameterizedType;
8import java.lang.reflect.Type;
9import java.lang.reflect.TypeVariable;
10
11public class Minifygeneric {
12
13 public static void main(String[] args) throws NoSuchMethodException, SecurityException, NoSuchFieldException {
14 for (TypeVariable<Class<Generic>> var : Generic.class.getTypeParameters()) {
15 System.out.println(var.getName());
16 Type bound = var.getBounds()[0];
17 System.out.println(((Class<?>) bound).getName().equals(AA.class.getName()));
18 }
19
20 Field f = Generic.class.getField("f");
21 ParameterizedType fieldType = (java.lang.reflect.ParameterizedType)f.getGenericType();
22 checkOneParameterType(fieldType, Generic.class, AA.class);
23
24 ParameterizedType methodReturnType =
25 (ParameterizedType) Generic.class.getMethod("get").getGenericReturnType();
26 checkOneParameterType(methodReturnType, Generic.class, AA.class);
27 }
28
29 private static void checkOneParameterType(ParameterizedType toCheck, Class<?> rawType,
30 Class<?>... bounds) {
31 System.out.println(((Class<?>) toCheck.getRawType()).getName()
32 .equals(rawType.getName()));
33 Type[] parameters = toCheck.getActualTypeArguments();
34 System.out.println(parameters.length);
35 TypeVariable<?> parameter = (TypeVariable<?>) parameters[0];
36 System.out.println(parameter.getName());
37 Type[] actualBounds = parameter.getBounds();
38 for (int i = 0; i < bounds.length; i++) {
39 System.out.println(((Class<?>) actualBounds[i]).getName().equals(bounds[i].getName()));
40 }
41 }
42}