本文整理汇总了Java中java.lang.reflect.Constructor.getGenericParameterTypes方法的典型用法代码示例。如果您正苦于以下问题:Java Constructor.getGenericParameterTypes方法的具体用法?Java Constructor.getGenericParameterTypes怎么用?Java Constructor.getGenericParameterTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Constructor
的用法示例。
在下文中一共展示了Constructor.getGenericParameterTypes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getParameterTypes
import java.lang.reflect.Constructor; //导入方法依赖的package包/类
/**
* Returns the resolved generic parameter types of {@code methodOrConstructor}.
*
* @param methodOrConstructor a method or constructor defined by this or any supertype.
* @since 2.0
*/
public List<TypeLiteral<?>> getParameterTypes(Member methodOrConstructor) {
Type[] genericParameterTypes;
if (methodOrConstructor instanceof Method) {
Method method = (Method) methodOrConstructor;
if (!method.getDeclaringClass().isAssignableFrom(rawType)) {
throw new IllegalArgumentException(method + " is not defined by a supertype of " + type);
}
genericParameterTypes = method.getGenericParameterTypes();
} else if (methodOrConstructor instanceof Constructor) {
Constructor constructor = (Constructor) methodOrConstructor;
if (!constructor.getDeclaringClass().isAssignableFrom(rawType)) {
throw new IllegalArgumentException(constructor + " does not construct a supertype of " + type);
}
genericParameterTypes = constructor.getGenericParameterTypes();
} else {
throw new IllegalArgumentException("Not a method or a constructor: " + methodOrConstructor);
}
return resolveAll(genericParameterTypes);
}
示例2: getParameterTypes
import java.lang.reflect.Constructor; //导入方法依赖的package包/类
/**
* Returns the resolved generic parameter types of {@code methodOrConstructor}.
*
* @param methodOrConstructor a method or constructor defined by this or any supertype.
* @since 2.0
*/
public List<TypeLiteral<?>> getParameterTypes(Member methodOrConstructor) {
Type[] genericParameterTypes;
if (methodOrConstructor instanceof Method) {
Method method = (Method) methodOrConstructor;
checkArgument(method.getDeclaringClass().isAssignableFrom(rawType),
"%s is not defined by a supertype of %s", method, type);
genericParameterTypes = method.getGenericParameterTypes();
} else if (methodOrConstructor instanceof Constructor) {
Constructor<?> constructor = (Constructor<?>) methodOrConstructor;
checkArgument(constructor.getDeclaringClass().isAssignableFrom(rawType),
"%s does not construct a supertype of %s", constructor, type);
genericParameterTypes = constructor.getGenericParameterTypes();
} else {
throw new IllegalArgumentException("Not a method or a constructor: " + methodOrConstructor);
}
return resolveAll(genericParameterTypes);
}