當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。