Here you can find the source of getGenericTypes(Constructor> targetConstructor, Integer constructorArgOrderingNumber)
Parameter | Description |
---|---|
targetConstructor | the target constructor |
constructorArgOrderingNumber | the constructor arg ordering number |
public static Type[] getGenericTypes(Constructor<?> targetConstructor, Integer constructorArgOrderingNumber)
//package com.java2s; /*/*from ww w . j a va2s .com*/ ORG Usurper is a random value object generator library Copyright (C) 2007 Pierre-Antoine Gr?goire This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { /** * Gets the generic types for a given constructor argument (specified by its ordering number). * * @param targetConstructor the target constructor * @param constructorArgOrderingNumber the constructor arg ordering number * * @return the generic types */ public static Type[] getGenericTypes(Constructor<?> targetConstructor, Integer constructorArgOrderingNumber) { Type[] genericParameterTypes = targetConstructor.getGenericParameterTypes(); ParameterizedType type = (ParameterizedType) genericParameterTypes[constructorArgOrderingNumber - 1]; return type.getActualTypeArguments(); } /** * Gets the generic types for a given field. * * @param attribute the attribute * * @return the generic types */ public static Type[] getGenericTypes(Field attribute) { ParameterizedType type = (ParameterizedType) attribute.getGenericType(); return type.getActualTypeArguments(); } }