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


Java Type.getClass方法代码示例

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

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:TypeUtils.java

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

示例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());
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:11,代码来源:ReflectionUtils.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:10,代码来源:TypeUtils.java

示例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;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:12,代码来源:TypeUtils.java

示例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());
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:42,代码来源:TypeFactory.java

示例8: AtomRequest

import java.lang.reflect.Type; //导入方法依赖的package包/类
AtomRequest(A a, Type t) {
    this.a = a;
    this.aClass = t.getClass();

    a.createClient();
}
 
开发者ID:shiburagi,项目名称:Atomic,代码行数:7,代码来源:AtomRequest.java


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