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


Java GenericArrayType类代码示例

本文整理汇总了Java中java.lang.reflect.GenericArrayType的典型用法代码示例。如果您正苦于以下问题:Java GenericArrayType类的具体用法?Java GenericArrayType怎么用?Java GenericArrayType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GenericArrayType类属于java.lang.reflect包,在下文中一共展示了GenericArrayType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: canonicalize

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
/**
 * Returns a type that is functionally equal but not necessarily equal according to {@link
 * Object#equals(Object) Object.equals()}.
 */
static Type canonicalize(Type type) {
  if (type instanceof Class) {
    Class<?> c = (Class<?>) type;
    return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c;

  } else if (type instanceof ParameterizedType) {
    if (type instanceof ParameterizedTypeImpl) return type;
    ParameterizedType p = (ParameterizedType) type;
    return new ParameterizedTypeImpl(p.getOwnerType(),
        p.getRawType(), p.getActualTypeArguments());

  } else if (type instanceof GenericArrayType) {
    if (type instanceof GenericArrayTypeImpl) return type;
    GenericArrayType g = (GenericArrayType) type;
    return new GenericArrayTypeImpl(g.getGenericComponentType());

  } else if (type instanceof WildcardType) {
    if (type instanceof WildcardTypeImpl) return type;
    WildcardType w = (WildcardType) type;
    return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());

  } else {
    return type; // This type is unsupported!
  }
}
 
开发者ID:hzsweers,项目名称:inspector,代码行数:30,代码来源:Types.java

示例2: getGenericClass

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
public static Class getGenericClass(ParameterizedType parameterizedType, int i) {
    Object genericClass = parameterizedType.getActualTypeArguments()[i];
    if (genericClass instanceof ParameterizedType) {
        // 处理多级泛型
        System.out.println("111111");
        return (Class) ((ParameterizedType) genericClass).getRawType();
    } else if (genericClass instanceof GenericArrayType) {
        // 处理数组泛型
        return (Class) ((GenericArrayType) genericClass).getGenericComponentType();
    } else if (genericClass instanceof TypeVariable) {
        // 处理泛型擦拭对象
        System.out.println("33333333");
        return (Class) getClass(((TypeVariable) genericClass).getBounds()[0], 0);
    } else {
        System.out.println("444444");
        return (Class) genericClass;
    }
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:19,代码来源:ClassReflectUtil.java

示例3: canonicalize

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
/**
 * Returns a type that is functionally equal but not necessarily equal
 * according to {@link Object#equals(Object) Object.equals()}. The returned
 * type is {@link java.io.Serializable}.
 */
public static Type canonicalize(Type type) {
  if (type instanceof Class) {
    Class<?> c = (Class<?>) type;
    return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c;

  } else if (type instanceof ParameterizedType) {
    ParameterizedType p = (ParameterizedType) type;
    return new ParameterizedTypeImpl(p.getOwnerType(),
        p.getRawType(), p.getActualTypeArguments());

  } else if (type instanceof GenericArrayType) {
    GenericArrayType g = (GenericArrayType) type;
    return new GenericArrayTypeImpl(g.getGenericComponentType());

  } else if (type instanceof WildcardType) {
    WildcardType w = (WildcardType) type;
    return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());

  } else {
    // type is either serializable as-is or unsupported
    return type;
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:$Gson$Types.java

示例4: createTypeLiteralBinding

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
/**
 * Converts a binding for a {@code Key<TypeLiteral<T>>} to the value {@code TypeLiteral<T>}. It's
 * a bit awkward because we have to pull out the inner type in the type literal.
 */
private <T> BindingImpl<TypeLiteral<T>> createTypeLiteralBinding(
    Key<TypeLiteral<T>> key, Errors errors) throws ErrorsException {
  Type typeLiteralType = key.getTypeLiteral().getType();
  if (!(typeLiteralType instanceof ParameterizedType)) {
    throw errors.cannotInjectRawTypeLiteral().toException();
  }

  ParameterizedType parameterizedType = (ParameterizedType) typeLiteralType;
  Type innerType = parameterizedType.getActualTypeArguments()[0];

  // this is unforunate. We don't support building TypeLiterals for type variable like 'T'. If
  // this proves problematic, we can probably fix TypeLiteral to support type variables
  if (!(innerType instanceof Class)
      && !(innerType instanceof GenericArrayType)
      && !(innerType instanceof ParameterizedType)) {
    throw errors.cannotInjectTypeLiteralOf(innerType).toException();
  }

  @SuppressWarnings("unchecked") // by definition, innerType == T, so this is safe
  TypeLiteral<T> value = (TypeLiteral<T>) TypeLiteral.get(innerType);
  InternalFactory<TypeLiteral<T>> factory = new ConstantFactory<TypeLiteral<T>>(
      Initializables.of(value));
  return new InstanceBindingImpl<TypeLiteral<T>>(this, key, SourceProvider.UNKNOWN_SOURCE,
      factory, ImmutableSet.<InjectionPoint>of(), value);
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:30,代码来源:InjectorImpl.java

示例5: getHttpEntityType

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
private Class<?> getHttpEntityType(MethodParameter methodParam) {
	Assert.isAssignable(HttpEntity.class, methodParam.getParameterType());
	ParameterizedType type = (ParameterizedType) methodParam.getGenericParameterType();
	if (type.getActualTypeArguments().length == 1) {
		Type typeArgument = type.getActualTypeArguments()[0];
		if (typeArgument instanceof Class) {
			return (Class<?>) typeArgument;
		}
		else if (typeArgument instanceof GenericArrayType) {
			Type componentType = ((GenericArrayType) typeArgument).getGenericComponentType();
			if (componentType instanceof Class) {
				// Surely, there should be a nicer way to do this
				Object array = Array.newInstance((Class<?>) componentType, 0);
				return array.getClass();
			}
		}
	}
	throw new IllegalArgumentException(
			"HttpEntity parameter (" + methodParam.getParameterName() + ") is not parameterized");

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:HandlerMethodInvoker.java

示例6: hasUnresolvableType

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
static boolean hasUnresolvableType(Type type) {
  if (type instanceof Class<?>) {
    return false;
  }
  if (type instanceof ParameterizedType) {
    ParameterizedType parameterizedType = (ParameterizedType) type;
    for (Type typeArgument : parameterizedType.getActualTypeArguments()) {
      if (hasUnresolvableType(typeArgument)) {
        return true;
      }
    }
    return false;
  }
  if (type instanceof GenericArrayType) {
    return hasUnresolvableType(((GenericArrayType) type).getGenericComponentType());
  }
  if (type instanceof TypeVariable) {
    return true;
  }
  if (type instanceof WildcardType) {
    return true;
  }
  String className = type == null ? "null" : type.getClass().getName();
  throw new IllegalArgumentException("Expected a Class, ParameterizedType, or "
      + "GenericArrayType, but <" + type + "> is of type " + className);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:Utils.java

示例7: resolveType

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
/**
 * Resolves all type variables in {@code type} and all downstream types and returns a
 * corresponding type with type variables resolved.
 */
public Type resolveType(Type type) {
  checkNotNull(type);
  if (type instanceof TypeVariable) {
    return typeTable.resolve((TypeVariable<?>) type);
  } else if (type instanceof ParameterizedType) {
    return resolveParameterizedType((ParameterizedType) type);
  } else if (type instanceof GenericArrayType) {
    return resolveGenericArrayType((GenericArrayType) type);
  } else if (type instanceof WildcardType) {
    return resolveWildcardType((WildcardType) type);
  } else {
    // if Class<?>, no resolution needed, we are done.
    return type;
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:20,代码来源:TypeResolver.java

示例8: getRawType

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
public static Class<?> getRawType(Type type) {
    if (type instanceof Class) {
        return (Class) type;
    }
    if (type instanceof ParameterizedType) {
        Type rawType = ((ParameterizedType) type).getRawType();
        C$Gson$Preconditions.checkArgument(rawType instanceof Class);
        return (Class) rawType;
    } else if (type instanceof GenericArrayType) {
        return Array.newInstance(C$Gson$Types.getRawType(((GenericArrayType) type)
                .getGenericComponentType()), 0).getClass();
    } else {
        if (type instanceof TypeVariable) {
            return Object.class;
        }
        if (type instanceof WildcardType) {
            return C$Gson$Types.getRawType(((WildcardType) type).getUpperBounds()[0]);
        }
        throw new IllegalArgumentException("Expected a Class, ParameterizedType, or " +
                "GenericArrayType, but <" + type + "> is of type " + (type == null ? "null" :
                type.getClass().getName()));
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:24,代码来源:C$Gson$Types.java

示例9: getElementType

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
/** If the type of the field is parameterized, returns the Class object representing the parameter type at the specified index,
 * null otherwise. */
public Class getElementType (int index) {
	Type genericType = field.getGenericType();
	if (genericType instanceof ParameterizedType) {
		Type[] actualTypes = ((ParameterizedType)genericType).getActualTypeArguments();
		if (actualTypes.length - 1 >= index) {
			Type actualType = actualTypes[index];
			if (actualType instanceof Class)
				return (Class)actualType;
			else if (actualType instanceof ParameterizedType)
				return (Class)((ParameterizedType)actualType).getRawType();
			else if (actualType instanceof GenericArrayType) {
				Type componentType = ((GenericArrayType)actualType).getGenericComponentType();
				if (componentType instanceof Class) return ArrayReflection.newInstance((Class)componentType, 0).getClass();
			}
		}
	}
	return null;
}
 
开发者ID:Guerra24,项目名称:NanoUI,代码行数:21,代码来源:Field.java

示例10: hashCode

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
/**
 * Returns the hashCode of {@code type}.
 */
public static int hashCode(Type type) {
    if (type instanceof Class) {
        // Class specifies hashCode().
        return type.hashCode();

    } else if (type instanceof ParameterizedType) {
        ParameterizedType p = (ParameterizedType) type;
        return Arrays.hashCode(p.getActualTypeArguments())
                ^ p.getRawType().hashCode()
                ^ hashCodeOrZero(p.getOwnerType());

    } else if (type instanceof GenericArrayType) {
        return hashCode(((GenericArrayType) type).getGenericComponentType());

    } else if (type instanceof WildcardType) {
        WildcardType w = (WildcardType) type;
        return Arrays.hashCode(w.getLowerBounds()) ^ Arrays.hashCode(w.getUpperBounds());

    } else {
        // This isn't a type we support. Probably a type variable
        return hashCodeOrZero(type);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:MoreTypes.java

示例11: hasUnresolvableType

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
static boolean hasUnresolvableType(Type type) {
    if (type instanceof Class<?>) {
        return false;
    }
    if (type instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) type;
        for (Type typeArgument : parameterizedType.getActualTypeArguments()) {
            if (hasUnresolvableType(typeArgument)) {
                return true;
            }
        }
        return false;
    }
    if (type instanceof GenericArrayType) {
        return hasUnresolvableType(((GenericArrayType) type).getGenericComponentType());
    }
    if (type instanceof TypeVariable) {
        return true;
    }
    if (type instanceof WildcardType) {
        return true;
    }
    String className = type == null ? "null" : type.getClass().getName();
    throw new IllegalArgumentException("Expected a Class, ParameterizedType, or "
            + "GenericArrayType, but <" + type + "> is of type " + className);
}
 
开发者ID:SKT-ThingPlug,项目名称:thingplug-sdk-android,代码行数:27,代码来源:MQTTUtils.java

示例12: getGenericClass

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
public static Class<?> getGenericClass(Class<?> cls, int i) {
    try {
        ParameterizedType parameterizedType = ((ParameterizedType) cls.getGenericInterfaces()[0]);
        Object genericClass = parameterizedType.getActualTypeArguments()[i];
        if (genericClass instanceof ParameterizedType) { // 处理多级泛型
            return (Class<?>) ((ParameterizedType) genericClass).getRawType();
        } else if (genericClass instanceof GenericArrayType) { // 处理数组泛型
            return (Class<?>) ((GenericArrayType) genericClass).getGenericComponentType();
        } else if (genericClass != null) {
            return (Class<?>) genericClass;
        }
    } catch (Throwable e) {
    }
    if (cls.getSuperclass() != null) {
        return getGenericClass(cls.getSuperclass(), i);
    } else {
        throw new IllegalArgumentException(cls.getName() + " generic type undefined!");
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:20,代码来源:ClassUtils.java

示例13: getGenericClass

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
public static Class getGenericClass(ParameterizedType parameterizedType, int i) {
    Object genericClass = parameterizedType.getActualTypeArguments()[i];
    if (genericClass instanceof ParameterizedType) { // 处理多级泛型
        return (Class) ((ParameterizedType) genericClass).getRawType();
    } else if (genericClass instanceof GenericArrayType) { // 处理数组泛型
        return (Class) ((GenericArrayType) genericClass).getGenericComponentType();
    } else if (genericClass instanceof TypeVariable) { // 处理泛型擦拭对象
        return (Class) getClass(((TypeVariable) genericClass).getBounds()[0], 0);
    } else {
        return (Class) genericClass;
    }
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:13,代码来源:ClassUtil.java

示例14: a

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
public static Type a(Type type) {
    if (type instanceof Class) {
        c cVar;
        Class cls = (Class) type;
        if (cls.isArray()) {
            cVar = new c(a(cls.getComponentType()));
        } else {
            Object obj = cls;
        }
        return cVar;
    } else if (type instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) type;
        return new d(parameterizedType.getOwnerType(), parameterizedType.getRawType(), parameterizedType.getActualTypeArguments());
    } else if (type instanceof GenericArrayType) {
        return new c(((GenericArrayType) type).getGenericComponentType());
    } else {
        if (!(type instanceof WildcardType)) {
            return type;
        }
        WildcardType wildcardType = (WildcardType) type;
        return new e(wildcardType.getUpperBounds(), wildcardType.getLowerBounds());
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:24,代码来源:b.java

示例15: createTypeLiteralBinding

import java.lang.reflect.GenericArrayType; //导入依赖的package包/类
/**
 * Converts a binding for a {@code Key<TypeLiteral<T>>} to the value {@code TypeLiteral<T>}. It's
 * a bit awkward because we have to pull out the inner type in the type literal.
 */
private <T> BindingImpl<TypeLiteral<T>> createTypeLiteralBinding(
        Key<TypeLiteral<T>> key, Errors errors) throws ErrorsException {
    Type typeLiteralType = key.getTypeLiteral().getType();
    if (!(typeLiteralType instanceof ParameterizedType)) {
        throw errors.cannotInjectRawTypeLiteral().toException();
    }

    ParameterizedType parameterizedType = (ParameterizedType) typeLiteralType;
    Type innerType = parameterizedType.getActualTypeArguments()[0];

    // this is unforunate. We don't support building TypeLiterals for type variable like 'T'. If
    // this proves problematic, we can probably fix TypeLiteral to support type variables
    if (!(innerType instanceof Class)
            && !(innerType instanceof GenericArrayType)
            && !(innerType instanceof ParameterizedType)) {
        throw errors.cannotInjectTypeLiteralOf(innerType).toException();
    }

    @SuppressWarnings("unchecked") // by definition, innerType == T, so this is safe
            TypeLiteral<T> value = (TypeLiteral<T>) TypeLiteral.get(innerType);
    InternalFactory<TypeLiteral<T>> factory = new ConstantFactory<>(
            Initializables.of(value));
    return new InstanceBindingImpl<>(this, key, SourceProvider.UNKNOWN_SOURCE,
            factory, ImmutableSet.<InjectionPoint>of(), value);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:30,代码来源:InjectorImpl.java


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