当前位置: 首页>>代码示例>>Java>>正文


Java Constructor.getGenericParameterTypes方法代码示例

本文整理汇总了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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:TypeLiteral.java

示例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);
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:28,代码来源:TypeLiteral.java


注:本文中的java.lang.reflect.Constructor.getGenericParameterTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。