本文整理汇总了Java中java.lang.reflect.WildcardType.getLowerBounds方法的典型用法代码示例。如果您正苦于以下问题:Java WildcardType.getLowerBounds方法的具体用法?Java WildcardType.getLowerBounds怎么用?Java WildcardType.getLowerBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.WildcardType
的用法示例。
在下文中一共展示了WildcardType.getLowerBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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()}.
*/
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!
}
}
示例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()}.
*/
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) {
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: 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());
}
}
示例6: 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!
}
}
示例7: 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
}
示例8: 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);
}
示例9: a
import java.lang.reflect.WildcardType; //导入方法依赖的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());
}
}
示例10: 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 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;
}
}
示例11: 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;
}
}
示例12: 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");
}
示例13: 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;
}
}
}
示例14: toString
import java.lang.reflect.WildcardType; //导入方法依赖的package包/类
public static String toString(Type type) {
if (type instanceof Class<?>) {
return ((Class) type).getName();
} else if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
Type[] arguments = parameterizedType.getActualTypeArguments();
Type ownerType = parameterizedType.getOwnerType();
StringBuilder stringBuilder = new StringBuilder();
if (ownerType != null) {
stringBuilder.append(toString(ownerType)).append(".");
}
stringBuilder.append(toString(parameterizedType.getRawType()));
if (arguments.length > 0) {
stringBuilder
.append("<")
.append(toString(arguments[0]));
for (int i = 1; i < arguments.length; i++) {
stringBuilder.append(", ").append(toString(arguments[i]));
}
}
return stringBuilder.append(">").toString();
} else if (type instanceof GenericArrayType) {
return toString(((GenericArrayType) type).getGenericComponentType()) + "[]";
} else if (type instanceof WildcardType) {
WildcardType wildcardType = (WildcardType) type;
Type[] lowerBounds = wildcardType.getLowerBounds();
Type[] upperBounds = wildcardType.getUpperBounds();
if (upperBounds.length != 1 || lowerBounds.length > 1) {
throw new UnsupportedOperationException("Unsupported wildcard type " + type);
}
if (lowerBounds.length == 1) {
if (upperBounds[0] != Object.class) {
throw new UnsupportedOperationException("Unsupported wildcard type " + type);
}
return "? super " + toString(lowerBounds[0]);
} else if (upperBounds[0] == Object.class) {
return "?";
} else {
return "? extends " + toString(upperBounds[0]);
}
} else {
return type.toString();
}
}
示例15: resolveWildcardType
import java.lang.reflect.WildcardType; //导入方法依赖的package包/类
private WildcardType resolveWildcardType(WildcardType type) {
Type[] lowerBounds = type.getLowerBounds();
Type[] upperBounds = type.getUpperBounds();
return new Types.WildcardTypeImpl(resolveTypes(lowerBounds), resolveTypes(upperBounds));
}