本文整理汇总了Java中java.lang.reflect.Type.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java Type.getClass方法的具体用法?Java Type.getClass怎么用?Java Type.getClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Type
的用法示例。
在下文中一共展示了Type.getClass方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isFullySpecified
import java.lang.reflect.Type; //导入方法依赖的package包/类
public static boolean isFullySpecified(Type type) {
checkNotNull(type);
if(type instanceof Class) {
return true;
} else if(type instanceof TypeVariable) {
return false;
} else if(type instanceof GenericArrayType) {
return isFullySpecified(((GenericArrayType) type).getGenericComponentType());
} else if(type instanceof WildcardType) {
final WildcardType wildcard = (WildcardType) type;
return Stream.of(wildcard.getLowerBounds()).allMatch(Types::isFullySpecified) &&
Stream.of(wildcard.getUpperBounds()).allMatch(Types::isFullySpecified);
} else if(type instanceof ParameterizedType) {
final ParameterizedType parameterized = (ParameterizedType) type;
return isFullySpecified(parameterized.getRawType()) &&
(parameterized.getOwnerType() == null || isFullySpecified(parameterized.getOwnerType())) &&
Stream.of(parameterized.getActualTypeArguments()).allMatch(Types::isFullySpecified);
} else {
throw new IllegalArgumentException("Unhandled metatype " + type.getClass());
}
}
示例2: getClass
import java.lang.reflect.Type; //导入方法依赖的package包/类
public static Class<?> getClass(Type type){
if(type.getClass() == Class.class){
return (Class<?>) type;
}
if(type instanceof ParameterizedType){
return getClass(((ParameterizedType) type).getRawType());
}
if(type instanceof TypeVariable){
Type boundType = ((TypeVariable<?>) type).getBounds()[0];
return (Class<?>) boundType;
}
if(type instanceof WildcardType){
Type[] upperBounds = ((WildcardType) type).getUpperBounds();
if (upperBounds.length == 1) {
return getClass(upperBounds[0]);
}
}
return Object.class;
}
示例3: formatTypeWithoutSpecialCharacter
import java.lang.reflect.Type; //导入方法依赖的package包/类
private static String formatTypeWithoutSpecialCharacter(Type type) {
if (type instanceof Class) {
Class clazz = (Class) type;
return clazz.getCanonicalName();
}
if (type instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) type;
String typeName = formatTypeWithoutSpecialCharacter(pType.getRawType());
for (Type typeArg : pType.getActualTypeArguments()) {
typeName += "_";
typeName += formatTypeWithoutSpecialCharacter(typeArg);
}
return typeName;
}
if (type instanceof GenericArrayType) {
GenericArrayType gaType = (GenericArrayType) type;
return formatTypeWithoutSpecialCharacter(gaType.getGenericComponentType()) + "_array";
}
throw new AJsoupReaderException("unsupported type: " + type + ", of class " + type.getClass());
}
示例4: getRawType
import java.lang.reflect.Type; //导入方法依赖的package包/类
public static Class<?> getRawType(final AnnotatedType annotatedType) {
final Type containerType = annotatedType.getType();
if (containerType instanceof Class) {
return (Class<?>) containerType;
} else if (containerType instanceof ParameterizedType) {
return (Class<?>) ((ParameterizedType) containerType).getRawType();
} else {
throw new ValidationException("Unknown type: " + containerType.getClass());
}
}
示例5: getClass
import java.lang.reflect.Type; //导入方法依赖的package包/类
public static Class<?> getClass(Type type) {
if (type.getClass() == Class.class) {
return (Class) type;
}
if (type instanceof ParameterizedType) {
return getClass(((ParameterizedType) type).getRawType());
}
return Object.class;
}
示例6: getClass
import java.lang.reflect.Type; //导入方法依赖的package包/类
public static Class<?> getClass(Type type) {
if (type.getClass() == Class.class) {
return (Class<?>) type;
}
if (type instanceof ParameterizedType) {
return getClass(((ParameterizedType) type).getRawType());
}
return Object.class;
}
示例7: getReifiedType
import java.lang.reflect.Type; //导入方法依赖的package包/类
private static ReifiedType getReifiedType(Type targetType, Collection<Type> variableTypes) {
if (targetType instanceof Class) {
if (Object.class.equals(targetType)) {
return OBJECT;
}
return new GenericsReifiedType((Class<?>) targetType);
}
if (targetType instanceof ParameterizedType) {
Type ata = ((ParameterizedType) targetType).getActualTypeArguments()[0];
return getReifiedType(ata, variableTypes);
}
if (targetType instanceof WildcardType) {
WildcardType wt = (WildcardType) targetType;
Type[] lowerBounds = wt.getLowerBounds();
if (ObjectUtils.isEmpty(lowerBounds)) {
// there's always an upper bound (Object)
Type upperBound = wt.getUpperBounds()[0];
return getReifiedType(upperBound, variableTypes);
}
return getReifiedType(lowerBounds[0], variableTypes);
}
if (targetType instanceof TypeVariable) {
TypeVariable<?> typeVariable = (TypeVariable<?>) targetType;
if (variableTypes.contains(targetType)) {
//Looped around on itself via a recursive Generics definition
return OBJECT;
}
variableTypes.add(targetType);
Type[] bounds = typeVariable.getBounds();
return getReifiedType(bounds[0], variableTypes);
}
if (targetType instanceof GenericArrayType) {
return getReifiedType(((GenericArrayType) targetType).getGenericComponentType(), variableTypes);
}
throw new IllegalArgumentException("Unknown type " + targetType.getClass());
}
示例8: AtomRequest
import java.lang.reflect.Type; //导入方法依赖的package包/类
AtomRequest(A a, Type t) {
this.a = a;
this.aClass = t.getClass();
a.createClient();
}