本文整理匯總了Java中java.lang.reflect.WildcardType.getUpperBounds方法的典型用法代碼示例。如果您正苦於以下問題:Java WildcardType.getUpperBounds方法的具體用法?Java WildcardType.getUpperBounds怎麽用?Java WildcardType.getUpperBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.WildcardType
的用法示例。
在下文中一共展示了WildcardType.getUpperBounds方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: canonicalize
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
public static Type canonicalize(Type type) {
if (type instanceof Class) {
GenericArrayTypeImpl genericArrayTypeImpl;
Class<?> c = (Class) type;
if (c.isArray()) {
genericArrayTypeImpl = new GenericArrayTypeImpl(C$Gson$Types.canonicalize(c
.getComponentType()));
} else {
Object obj = c;
}
return genericArrayTypeImpl;
} else if (type instanceof ParameterizedType) {
ParameterizedType p = (ParameterizedType) type;
return new ParameterizedTypeImpl(p.getOwnerType(), p.getRawType(), p
.getActualTypeArguments());
} else if (type instanceof GenericArrayType) {
return new GenericArrayTypeImpl(((GenericArrayType) type).getGenericComponentType());
} else {
if (!(type instanceof WildcardType)) {
return type;
}
WildcardType w = (WildcardType) type;
return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());
}
}
示例2: canonicalize
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
/**
* Returns a type that is functionally equal but not necessarily equal according to {@link
* Object#equals(Object) Object.equals()}.
*/
private 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!
}
}
示例3: canonicalize
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
public static Type canonicalize(Type type) {
if (type instanceof Class) {
Class<?> c = (Class) type;
return c.isArray() ? new GenericArrayTypeImpl(C$Gson$Types.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) {
return new GenericArrayTypeImpl(((GenericArrayType) type).getGenericComponentType());
} else {
if (!(type instanceof WildcardType)) {
return type;
}
WildcardType w = (WildcardType) type;
return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());
}
}
示例4: canonicalize
import java.lang.reflect.WildcardType; //導入方法依賴的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;
}
}
示例5: inferTypes
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
private static Class<?>[] inferTypes(Class<?> propertyType, Class<?>[] annotationTypes, Type genericType) {
if (annotationTypes.length > 0) { return annotationTypes; }
if (propertyType.isArray()) { return new Class<?>[] { propertyType.getComponentType() }; }
if (CommandLine.isMultiValue(propertyType)) {
if (genericType instanceof ParameterizedType) {// e.g. Map<Long, ? extends Number>
ParameterizedType parameterizedType = (ParameterizedType) genericType;
Type[] paramTypes = parameterizedType.getActualTypeArguments(); // e.g. ? extends Number
Class<?>[] result = new Class<?>[paramTypes.length];
for (int i = 0; i < paramTypes.length; i++) {
if (paramTypes[i] instanceof Class) { result[i] = (Class<?>) paramTypes[i]; continue; } // e.g. Long
if (paramTypes[i] instanceof WildcardType) { // e.g. ? extends Number
WildcardType wildcardType = (WildcardType) paramTypes[i];
Type[] lower = wildcardType.getLowerBounds(); // e.g. []
if (lower.length > 0 && lower[0] instanceof Class) { result[i] = (Class<?>) lower[0]; continue; }
Type[] upper = wildcardType.getUpperBounds(); // e.g. Number
if (upper.length > 0 && upper[0] instanceof Class) { result[i] = (Class<?>) upper[0]; continue; }
}
Arrays.fill(result, String.class); return result; // too convoluted generic type, giving up
}
return result; // we inferred all types from ParameterizedType
}
return new Class<?>[] {String.class, String.class}; // field is multi-value but not ParameterizedType
}
return new Class<?>[] {propertyType}; // not a multi-value field
}
示例6: getCollectionItemClass
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
public static Class<?> getCollectionItemClass(Type fieldType){
if(fieldType instanceof ParameterizedType){
Class<?> itemClass;
Type actualTypeArgument = ((ParameterizedType) fieldType).getActualTypeArguments()[0];
if(actualTypeArgument instanceof WildcardType){
WildcardType wildcardType = (WildcardType) actualTypeArgument;
Type[] upperBounds = wildcardType.getUpperBounds();
if(upperBounds.length == 1){
actualTypeArgument = upperBounds[0];
}
}
if(actualTypeArgument instanceof Class){
itemClass = (Class<?>) actualTypeArgument;
if(!Modifier.isPublic(itemClass.getModifiers())){
throw new JSONException("can not create ASMParser");
}
} else{
throw new JSONException("can not create ASMParser");
}
return itemClass;
}
return Object.class;
}
示例7: getTypeParameter
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
@Nullable
public static Class<?> getTypeParameter(java.lang.reflect.Type type, int index) {
if (type instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) type;
java.lang.reflect.Type[] targs = ptype.getActualTypeArguments();
if (targs[index] instanceof WildcardType) {
WildcardType wildcardType = (WildcardType) targs[index];
if (wildcardType.getUpperBounds()[0] instanceof Class){
return (Class<?>) wildcardType.getUpperBounds()[0];
}else if (wildcardType.getUpperBounds()[0] instanceof ParameterizedType){
return (Class<?>) ((ParameterizedType) wildcardType.getUpperBounds()[0]).getRawType();
}else{
return Object.class;
}
} else if (targs[index] instanceof TypeVariable<?>) {
return (Class<?>) ((TypeVariable<?>) targs[index]).getGenericDeclaration();
} else if (targs[index] instanceof ParameterizedType) {
return (Class<?>) ((ParameterizedType) targs[index]).getRawType();
} else {
return (Class<?>) targs[index];
}
}
return null;
}
示例8: canonicalize
import java.lang.reflect.WildcardType; //導入方法依賴的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 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 CompositeType) {
return type;
} 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;
}
}
示例9: ArrayListTypeFieldDeserializer
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
public ArrayListTypeFieldDeserializer(ParserConfig mapping, Class<?> clazz, FieldInfo fieldInfo){
super(clazz, fieldInfo);
Type fieldType = fieldInfo.fieldType;
if (fieldType instanceof ParameterizedType) {
Type argType = ((ParameterizedType) fieldInfo.fieldType).getActualTypeArguments()[0];
if (argType instanceof WildcardType) {
WildcardType wildcardType = (WildcardType) argType;
Type[] upperBounds = wildcardType.getUpperBounds();
if (upperBounds.length == 1) {
argType = upperBounds[0];
}
}
this.itemType = argType;
} else {
this.itemType = Object.class;
}
}
示例10: newArrayType
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
/** Returns the array type of {@code componentType}. */
static Type newArrayType(Type componentType) {
if (componentType instanceof WildcardType) {
WildcardType wildcard = (WildcardType) componentType;
Type[] lowerBounds = wildcard.getLowerBounds();
checkArgument(lowerBounds.length <= 1, "Wildcard cannot have more than one lower bounds.");
if (lowerBounds.length == 1) {
return supertypeOf(newArrayType(lowerBounds[0]));
} else {
Type[] upperBounds = wildcard.getUpperBounds();
checkArgument(upperBounds.length == 1, "Wildcard should have only one upper bound.");
return subtypeOf(newArrayType(upperBounds[0]));
}
}
return JavaVersion.CURRENT.newArrayType(componentType);
}
示例11: getElementType
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
private static Type getElementType(ParameterizedType type, int index) {
Type elementType = type.getActualTypeArguments()[index];
if (elementType instanceof WildcardType) {
WildcardType wildcardType = (WildcardType) elementType;
return wildcardType.getUpperBounds()[0];
}
return elementType;
}
示例12: getDeserializer
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
public ObjectDeserializer getDeserializer(Type type) {
ObjectDeserializer derializer = this.deserializers.get(type);
if (derializer != null) {
return derializer;
}
if (type instanceof Class<?>) {
return getDeserializer((Class<?>) type, type);
}
if (type instanceof ParameterizedType) {
Type rawType = ((ParameterizedType) type).getRawType();
if (rawType instanceof Class<?>) {
return getDeserializer((Class<?>) rawType, type);
} else {
return getDeserializer(rawType);
}
}
if (type instanceof WildcardType) {
WildcardType wildcardType = (WildcardType) type;
Type[] upperBounds = wildcardType.getUpperBounds();
if (upperBounds.length == 1) {
Type upperBoundType = upperBounds[0];
return getDeserializer(upperBoundType);
}
}
return JavaObjectDeserializer.instance;
}
示例13: canonicalize
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
/**
* Returns a type that is functionally equal but not necessarily equal
* according to {@link Object#equals(Object) Object.equals()}.
*/
public static Type canonicalize(Type type) {
if (type instanceof ParameterizedTypeImpl
|| type instanceof GenericArrayTypeImpl
|| type instanceof WildcardTypeImpl) {
return type;
} 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 Class && ((Class<?>) type).isArray()) {
Class<?> c = (Class<?>) type;
return new GenericArrayTypeImpl(c.getComponentType());
} 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;
}
}
示例14: capture
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
Type capture(Type type) {
checkNotNull(type);
if (type instanceof Class) {
return type;
}
if (type instanceof TypeVariable) {
return type;
}
if (type instanceof GenericArrayType) {
GenericArrayType arrayType = (GenericArrayType) type;
return Types.newArrayType(capture(arrayType.getGenericComponentType()));
}
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
return Types.newParameterizedTypeWithOwner(
captureNullable(parameterizedType.getOwnerType()),
(Class<?>) parameterizedType.getRawType(),
capture(parameterizedType.getActualTypeArguments()));
}
if (type instanceof WildcardType) {
WildcardType wildcardType = (WildcardType) type;
Type[] lowerBounds = wildcardType.getLowerBounds();
if (lowerBounds.length == 0) { // ? extends something changes to capture-of
Type[] upperBounds = wildcardType.getUpperBounds();
String name =
"capture#"
+ id.incrementAndGet()
+ "-of ? extends "
+ Joiner.on('&').join(upperBounds);
return Types.newArtificialTypeVariable(
WildcardCapturer.class, name, wildcardType.getUpperBounds());
} else {
// TODO(benyu): handle ? super T somehow.
return type;
}
}
throw new AssertionError("must have been one of the known types");
}
示例15: resolve
import java.lang.reflect.WildcardType; //導入方法依賴的package包/類
public static Type resolve(Type context, Class<?> contextRawType, Type toResolve) {
while (toResolve instanceof TypeVariable) {
TypeVariable<?> typeVariable = (TypeVariable) toResolve;
toResolve = C$Gson$Types.resolveTypeVariable(context, contextRawType, typeVariable);
if (toResolve == typeVariable) {
return toResolve;
}
}
Type componentType;
Type newComponentType;
if ((toResolve instanceof Class) && ((Class) toResolve).isArray()) {
Class<?> original = (Class) toResolve;
componentType = original.getComponentType();
newComponentType = C$Gson$Types.resolve(context, contextRawType, componentType);
if (componentType != newComponentType) {
original = C$Gson$Types.arrayOf(newComponentType);
}
return original;
} else if (toResolve instanceof GenericArrayType) {
GenericArrayType original2 = (GenericArrayType) toResolve;
componentType = original2.getGenericComponentType();
newComponentType = C$Gson$Types.resolve(context, contextRawType, componentType);
if (componentType != newComponentType) {
return C$Gson$Types.arrayOf(newComponentType);
}
return original2;
} else if (toResolve instanceof ParameterizedType) {
ParameterizedType original3 = (ParameterizedType) toResolve;
Type ownerType = original3.getOwnerType();
Type newOwnerType = C$Gson$Types.resolve(context, contextRawType, ownerType);
boolean changed = newOwnerType != ownerType;
Type[] args = original3.getActualTypeArguments();
int length = args.length;
for (int t = 0; t < length; t++) {
Type resolvedTypeArgument = C$Gson$Types.resolve(context, contextRawType, args[t]);
if (resolvedTypeArgument != args[t]) {
if (!changed) {
args = (Type[]) args.clone();
changed = true;
}
args[t] = resolvedTypeArgument;
}
}
if (changed) {
return C$Gson$Types.newParameterizedTypeWithOwner(newOwnerType, original3
.getRawType(), args);
}
return original3;
} else if (!(toResolve instanceof WildcardType)) {
return toResolve;
} else {
WildcardType original4 = (WildcardType) toResolve;
Type[] originalLowerBound = original4.getLowerBounds();
Type[] originalUpperBound = original4.getUpperBounds();
if (originalLowerBound.length == 1) {
Type lowerBound = C$Gson$Types.resolve(context, contextRawType,
originalLowerBound[0]);
if (lowerBound != originalLowerBound[0]) {
return C$Gson$Types.supertypeOf(lowerBound);
}
return original4;
} else if (originalUpperBound.length != 1) {
return original4;
} else {
Type upperBound = C$Gson$Types.resolve(context, contextRawType,
originalUpperBound[0]);
if (upperBound != originalUpperBound[0]) {
return C$Gson$Types.subtypeOf(upperBound);
}
return original4;
}
}
}