java.lang.reflect.Constructor.getTypeParameters()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中java.lang.reflect.Constructor.getTypeParameters()方法的一些代码示例,展示了Constructor.getTypeParameters()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Constructor.getTypeParameters()方法的具体详情如下:
包路径:java.lang.reflect.Constructor
类名称:Constructor
方法名:getTypeParameters

Constructor.getTypeParameters介绍

[英]Returns an array of TypeVariable objects that represent the type variables declared by the generic declaration represented by this GenericDeclaration object, in declaration order. Returns an array of length 0 if the underlying generic declaration declares no type variables.
[中]返回TypeVariable对象数组,这些对象按声明顺序表示由此GenericDeclaration对象表示的泛型声明声明的类型变量。如果基础泛型声明未声明任何类型变量,则返回长度为0的数组。

代码示例

代码示例来源:origin: spring-projects/spring-loaded

public static TypeVariable[] callGetTypeParameters(Constructor thiz) {
  return thiz.getTypeParameters();
}

代码示例来源:origin: google/guava

/**
 * {@inheritDoc}
 *
 * <p>{@code [<E>]} will be returned for ArrayList's constructor. When both the class and the
 * constructor have type parameters, the class parameters are prepended before those of the
 * constructor's. This is an arbitrary rule since no existing language spec mandates one way or
 * the other. From the declaration syntax, the class type parameter appears first, but the call
 * syntax may show up in opposite order such as {@code new <A>Foo<B>()}.
 */
@Override
public final TypeVariable<?>[] getTypeParameters() {
 TypeVariable<?>[] declaredByClass = getDeclaringClass().getTypeParameters();
 TypeVariable<?>[] declaredByConstructor = constructor.getTypeParameters();
 TypeVariable<?>[] result =
   new TypeVariable<?>[declaredByClass.length + declaredByConstructor.length];
 System.arraycopy(declaredByClass, 0, result, 0, declaredByClass.length);
 System.arraycopy(
   declaredByConstructor, 0, result, declaredByClass.length, declaredByConstructor.length);
 return result;
}

代码示例来源:origin: prestodb/presto

/**
 * {@inheritDoc}
 *
 * <p>{@code [<E>]} will be returned for ArrayList's constructor. When both the class and the
 * constructor have type parameters, the class parameters are prepended before those of the
 * constructor's. This is an arbitrary rule since no existing language spec mandates one way or
 * the other. From the declaration syntax, the class type parameter appears first, but the call
 * syntax may show up in opposite order such as {@code new <A>Foo<B>()}.
 */
@Override
public final TypeVariable<?>[] getTypeParameters() {
 TypeVariable<?>[] declaredByClass = getDeclaringClass().getTypeParameters();
 TypeVariable<?>[] declaredByConstructor = constructor.getTypeParameters();
 TypeVariable<?>[] result =
   new TypeVariable<?>[declaredByClass.length + declaredByConstructor.length];
 System.arraycopy(declaredByClass, 0, result, 0, declaredByClass.length);
 System.arraycopy(
   declaredByConstructor, 0, result, declaredByClass.length, declaredByConstructor.length);
 return result;
}

代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl

/**
 * As per [JACKSON-468], we need to also allow declaration of local
 * type bindings; mostly it will allow defining bounds.
 */
@Override
public JavaType getType(TypeBindings bindings)
{
  return getType(bindings, _constructor.getTypeParameters());
}

代码示例来源:origin: wildfly/wildfly

/**
 * {@inheritDoc}
 *
 * <p>{@code [<E>]} will be returned for ArrayList's constructor. When both the class and the
 * constructor have type parameters, the class parameters are prepended before those of the
 * constructor's. This is an arbitrary rule since no existing language spec mandates one way or
 * the other. From the declaration syntax, the class type parameter appears first, but the call
 * syntax may show up in opposite order such as {@code new <A>Foo<B>()}.
 */
@Override
public final TypeVariable<?>[] getTypeParameters() {
 TypeVariable<?>[] declaredByClass = getDeclaringClass().getTypeParameters();
 TypeVariable<?>[] declaredByConstructor = constructor.getTypeParameters();
 TypeVariable<?>[] result =
   new TypeVariable<?>[declaredByClass.length + declaredByConstructor.length];
 System.arraycopy(declaredByClass, 0, result, 0, declaredByClass.length);
 System.arraycopy(
   declaredByConstructor, 0, result, declaredByClass.length, declaredByConstructor.length);
 return result;
}

代码示例来源:origin: google/guava

public void testConstructor_returnType_hasTypeParameter() throws Exception {
 @SuppressWarnings("rawtypes") // Foo.class for Foo<T> is always raw type
 Class<WithConstructorAndTypeParameter> type = WithConstructorAndTypeParameter.class;
 @SuppressWarnings("rawtypes") // Foo.class
 Constructor<WithConstructorAndTypeParameter> constructor = type.getDeclaredConstructor();
 Invokable<?, ?> factory = Invokable.from(constructor);
 assertThat(factory.getTypeParameters()).hasLength(2);
 assertEquals(type.getTypeParameters()[0], factory.getTypeParameters()[0]);
 assertEquals(constructor.getTypeParameters()[0], factory.getTypeParameters()[1]);
 ParameterizedType returnType = (ParameterizedType) factory.getReturnType().getType();
 assertEquals(type, returnType.getRawType());
 assertEquals(
   ImmutableList.copyOf(type.getTypeParameters()),
   ImmutableList.copyOf(returnType.getActualTypeArguments()));
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * As per [JACKSON-468], we need to also allow declaration of local
 * type bindings; mostly it will allow defining bounds.
 */
@Override
public JavaType getType(TypeBindings bindings)
{
  return getType(bindings, _constructor.getTypeParameters());
}

代码示例来源:origin: INRIA/spoon

@Override
public <T> void visitConstructor(Constructor<T> constructor) {
  for (Annotation annotation : constructor.getDeclaredAnnotations()) {
    visitAnnotation(annotation);
  }
  int nrEnclosingClasses = getNumberOfEnclosingClasses(constructor.getDeclaringClass());
  for (RtParameter parameter : RtParameter.parametersOf(constructor)) {
    //ignore implicit parameters of enclosing classes
    if (nrEnclosingClasses > 0) {
      nrEnclosingClasses--;
      continue;
    }
    visitParameter(parameter);
  }
  for (TypeVariable<Constructor<T>> aTypeParameter : constructor.getTypeParameters()) {
    visitTypeParameter(aTypeParameter);
  }
  for (Class<?> exceptionType : constructor.getExceptionTypes()) {
    visitTypeReference(CtRole.THROWN, exceptionType);
  }
}

代码示例来源:origin: errai/errai

@Override
public MetaTypeVariable[] getTypeParameters() {
 if (_typeParameters != null) return _typeParameters;
 return _typeParameters = JavaReflectionUtil.fromTypeVariable(constructor.getTypeParameters());
}

代码示例来源:origin: org.codehaus.jackson/jackson-mapper-lgpl

/**
 * As per [JACKSON-468], we need to also allow declaration of local
 * type bindings; mostly it will allow defining bounds.
 */
@Override
public JavaType getType(TypeBindings bindings)
{
  return getType(bindings, _constructor.getTypeParameters());
}

代码示例来源:origin: org.jboss.errai/errai-codegen

@Override
public MetaTypeVariable[] getTypeParameters() {
 if (_typeParameters != null) return _typeParameters;
 return _typeParameters = JavaReflectionUtil.fromTypeVariable(constructor.getTypeParameters());
}

代码示例来源:origin: com.alibaba.edas.acm/acm-sdk

/**
 * As per [JACKSON-468], we need to also allow declaration of local
 * type bindings; mostly it will allow defining bounds.
 */
@Override
public JavaType getType(TypeBindings bindings)
{
  return getType(bindings, _constructor.getTypeParameters());
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

/**
 * As per [JACKSON-468], we need to also allow declaration of local
 * type bindings; mostly it will allow defining bounds.
 */
@Override
public JavaType getType(TypeBindings bindings)
{
  return getType(bindings, _constructor.getTypeParameters());
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * As per [JACKSON-468], we need to also allow declaration of local
 * type bindings; mostly it will allow defining bounds.
 */
@Override
public JavaType getType(TypeBindings bindings)
{
  return getType(bindings, _constructor.getTypeParameters());
}

代码示例来源:origin: org.apache.hadoop/hadoop-aws-tlnd

/**
 * As per [JACKSON-468], we need to also allow declaration of local
 * type bindings; mostly it will allow defining bounds.
 */
@Override
public JavaType getType(TypeBindings bindings)
{
  return getType(bindings, _constructor.getTypeParameters());
}

代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind

/**
 * As per [JACKSON-468], we need to also allow declaration of local
 * type bindings; mostly it will allow defining bounds.
 */
@Override
public JavaType getType(TypeBindings bindings)
{
  return getType(bindings, _constructor.getTypeParameters());
}

代码示例来源:origin: ovea-deprecated/jetty-session-redis

/**
 * As per [JACKSON-468], we need to also allow declaration of local
 * type bindings; mostly it will allow defining bounds.
 */
@Override
public JavaType getType(TypeBindings bindings)
{
  return getType(bindings, _constructor.getTypeParameters());
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * As per [JACKSON-468], we need to also allow declaration of local
 * type bindings; mostly it will allow defining bounds.
 */
@Override
public JavaType getType(TypeBindings bindings)
{
  return getType(bindings, _constructor.getTypeParameters());
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

/**
 * As per [JACKSON-468], we need to also allow declaration of local
 * type bindings; mostly it will allow defining bounds.
 */
@Override
public JavaType getType(TypeBindings bindings)
{
  return getType(bindings, _constructor.getTypeParameters());
}

代码示例来源:origin: org.gradle/gradle-model-core

/**
 * Generates the signature for the given constructor
 */
public static String signature(Constructor<?> constructor) {
  StringBuilder builder = new StringBuilder();
  visitFormalTypeParameters(builder, constructor.getTypeParameters());
  visitParameters(builder, constructor.getGenericParameterTypes());
  builder.append("V");
  visitExceptions(builder, constructor.getGenericExceptionTypes());
  return builder.toString();
}

相关文章