本文整理了Java中com.google.common.reflect.TypeToken.getComponentType()
方法的一些代码示例,展示了TypeToken.getComponentType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TypeToken.getComponentType()
方法的具体详情如下:
包路径:com.google.common.reflect.TypeToken
类名称:TypeToken
方法名:getComponentType
[英]Returns the array component type if this type represents an array ( int[], T[], []> etc.), or else null is returned.
[中]如果此类型表示数组(int[]、T[]、[]>等),则返回数组组件类型,否则返回null。
代码示例来源:origin: google/guava
/**
* Returns true if this type is known to be an array type, such as {@code int[]}, {@code T[]},
* {@code <? extends Map<String, Integer>[]>} etc.
*/
public final boolean isArray() {
return getComponentType() != null;
}
代码示例来源:origin: google/j2objc
/**
* Returns true if this type is known to be an array type, such as {@code int[]}, {@code T[]},
* {@code <? extends Map<String, Integer>[]>} etc.
*/
public final boolean isArray() {
return getComponentType() != null;
}
代码示例来源:origin: wildfly/wildfly
/**
* Returns true if this type is known to be an array type, such as {@code int[]}, {@code T[]},
* {@code <? extends Map<String, Integer>[]>} etc.
*/
public final boolean isArray() {
return getComponentType() != null;
}
代码示例来源:origin: google/guava
private TypeToken<? extends T> getArraySubtype(Class<?> subclass) {
// array is covariant. component type is subtype, so is the array type.
TypeToken<?> componentSubtype = getComponentType().getSubtype(subclass.getComponentType());
@SuppressWarnings("unchecked") // component type is subtype, so is array type.
TypeToken<? extends T> result =
(TypeToken<? extends T>)
// If we are passed with int[].class, don't turn it to GenericArrayType
of(newArrayClassOrGenericArrayType(componentSubtype.runtimeType));
return result;
}
代码示例来源:origin: google/guava
private TypeToken<? super T> getArraySupertype(Class<? super T> supertype) {
// with component type, we have lost generic type information
// Use raw type so that compiler allows us to call getSupertype()
@SuppressWarnings("rawtypes")
TypeToken componentType =
checkNotNull(getComponentType(), "%s isn't a super type of %s", supertype, this);
// array is covariant. component type is super type, so is the array type.
@SuppressWarnings("unchecked") // going from raw type back to generics
TypeToken<?> componentSupertype = componentType.getSupertype(supertype.getComponentType());
@SuppressWarnings("unchecked") // component type is super type, so is array type.
TypeToken<? super T> result =
(TypeToken<? super T>)
// If we are passed with int[].class, don't turn it to GenericArrayType
of(newArrayClassOrGenericArrayType(componentSupertype.runtimeType));
return result;
}
代码示例来源:origin: google/j2objc
private TypeToken<? extends T> getArraySubtype(Class<?> subclass) {
// array is covariant. component type is subtype, so is the array type.
TypeToken<?> componentSubtype = getComponentType().getSubtype(subclass.getComponentType());
@SuppressWarnings("unchecked") // component type is subtype, so is array type.
TypeToken<? extends T> result =
(TypeToken<? extends T>)
// If we are passed with int[].class, don't turn it to GenericArrayType
of(newArrayClassOrGenericArrayType(componentSubtype.runtimeType));
return result;
}
代码示例来源:origin: wildfly/wildfly
private TypeToken<? extends T> getArraySubtype(Class<?> subclass) {
// array is covariant. component type is subtype, so is the array type.
TypeToken<?> componentSubtype = getComponentType().getSubtype(subclass.getComponentType());
@SuppressWarnings("unchecked") // component type is subtype, so is array type.
TypeToken<? extends T> result =
(TypeToken<? extends T>)
// If we are passed with int[].class, don't turn it to GenericArrayType
of(newArrayClassOrGenericArrayType(componentSubtype.runtimeType));
return result;
}
代码示例来源:origin: wildfly/wildfly
private TypeToken<? super T> getArraySupertype(Class<? super T> supertype) {
// with component type, we have lost generic type information
// Use raw type so that compiler allows us to call getSupertype()
@SuppressWarnings("rawtypes")
TypeToken componentType =
checkNotNull(getComponentType(), "%s isn't a super type of %s", supertype, this);
// array is covariant. component type is super type, so is the array type.
@SuppressWarnings("unchecked") // going from raw type back to generics
TypeToken<?> componentSupertype = componentType.getSupertype(supertype.getComponentType());
@SuppressWarnings("unchecked") // component type is super type, so is array type.
TypeToken<? super T> result =
(TypeToken<? super T>)
// If we are passed with int[].class, don't turn it to GenericArrayType
of(newArrayClassOrGenericArrayType(componentSupertype.runtimeType));
return result;
}
代码示例来源:origin: google/guava
public void testGetComponentType_arrayClasses() {
assertEquals(Object.class, TypeToken.of(Object[].class).getComponentType().getType());
assertEquals(Object[].class, TypeToken.of(Object[][].class).getComponentType().getType());
assertEquals(char.class, TypeToken.of(char[].class).getComponentType().getType());
assertEquals(char[].class, TypeToken.of(char[][].class).getComponentType().getType());
assertEquals(byte.class, TypeToken.of(byte[].class).getComponentType().getType());
assertEquals(short.class, TypeToken.of(short[].class).getComponentType().getType());
assertEquals(int.class, TypeToken.of(int[].class).getComponentType().getType());
assertEquals(long.class, TypeToken.of(long[].class).getComponentType().getType());
assertEquals(float.class, TypeToken.of(float[].class).getComponentType().getType());
assertEquals(double.class, TypeToken.of(double[].class).getComponentType().getType());
assertNull(TypeToken.of(Object.class).getComponentType());
assertNull(TypeToken.of(void.class).getComponentType());
}
代码示例来源:origin: google/guava
TypeToken<?> componentType = type.getComponentType();
Object array = Array.newInstance(componentType.getRawType(), 1);
Array.set(array, 0, generate(componentType));
代码示例来源:origin: google/guava
public void testGetComponentType_wildcardType() {
assertEquals(
Types.subtypeOf(Object.class),
TypeToken.of(Types.subtypeOf(Object[].class)).getComponentType().getType());
assertEquals(
Types.subtypeOf(Object[].class),
Types.newArrayType(
TypeToken.of(Types.subtypeOf(Object[].class)).getComponentType().getType()));
assertEquals(
int.class, TypeToken.of(Types.subtypeOf(int[].class)).getComponentType().getType());
assertNull(TypeToken.of(Types.subtypeOf(Object.class)).getComponentType());
assertNull(TypeToken.of(Types.supertypeOf(Object[].class)).getComponentType());
}
代码示例来源:origin: google/guava
public <T> void testGetComponentType_genericArrayClasses() {
assertNull(TypeToken.of(new TypeCapture<T>() {}.capture()).getComponentType());
assertEquals(
TypeToken.of(new TypeCapture<T>() {}.capture()),
new TypeToken<T[]>() {}.getComponentType());
assertEquals(new TypeToken<T[]>() {}, new TypeToken<T[][]>() {}.getComponentType());
}
代码示例来源:origin: com.google.guava/guava-jdk5
/**
* Returns true if this type is known to be an array type, such as {@code int[]}, {@code T[]},
* {@code <? extends Map<String, Integer>[]>} etc.
*/
public final boolean isArray() {
return getComponentType() != null;
}
代码示例来源:origin: Nextdoor/bender
/**
* Returns true if this type is known to be an array type, such as {@code int[]}, {@code T[]},
* {@code <? extends Map<String, Integer>[]>} etc.
*/
public final boolean isArray() {
return getComponentType() != null;
}
代码示例来源:origin: org.hudsonci.lib.guava/guava
private TypeToken<? extends T> getArraySubtype(Class<?> subclass) {
// array is covariant. component type is subtype, so is the array type.
TypeToken<?> componentSubtype = getComponentType()
.getSubtype(subclass.getComponentType());
@SuppressWarnings("unchecked") // component type is subtype, so is array type.
TypeToken<? extends T> result = (TypeToken<? extends T>)
// If we are passed with int[].class, don't turn it to GenericArrayType
of(newArrayClassOrGenericArrayType(componentSubtype.runtimeType));
return result;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics
private TypeToken<? extends T> getArraySubtype(Class<?> subclass) {
// array is covariant. component type is subtype, so is the array type.
TypeToken<?> componentSubtype = getComponentType()
.getSubtype(subclass.getComponentType());
@SuppressWarnings("unchecked") // component type is subtype, so is array type.
TypeToken<? extends T> result = (TypeToken<? extends T>)
// If we are passed with int[].class, don't turn it to GenericArrayType
of(newArrayClassOrGenericArrayType(componentSubtype.runtimeType));
return result;
}
代码示例来源:origin: joel-costigliola/assertj-assertions-generator
public String getElementAssertTypeName() {
String packageName = owningTypePackageName();
TypeToken<?> elementType = valueType.getComponentType();
return elementType == null ? null : getAssertType(elementType, packageName);
}
代码示例来源:origin: OpenMods/OpenModsLib
@Override
public IStreamSerializer<?> getSerializer(Class<?> cls) {
if (cls.isArray()) {
final TypeToken<?> componentCls = TypeToken.of(cls).getComponentType();
return componentCls.isPrimitive()
? createPrimitiveSerializer(componentCls)
: createNullableSerializer(componentCls);
}
return null;
}
代码示例来源:origin: com.gitee.l0km/swift-service-parser
public boolean isLongArray(Type type){
TypeToken<?> typeToken = TypeToken.of(type);
return typeToken.isArray() && isLong(typeToken.getComponentType().getType());
}
public boolean isTypeOfDao(Type type){
代码示例来源:origin: com.google.guava/guava-tests
public void testGetComponentType_wildcardType() {
assertEquals(Types.subtypeOf(Object.class),
TypeToken.of(Types.subtypeOf(Object[].class)).getComponentType().getType());
assertEquals(Types.subtypeOf(Object[].class),
Types.newArrayType(
TypeToken.of(Types.subtypeOf(Object[].class)).getComponentType().getType()));
assertEquals(int.class,
TypeToken.of(Types.subtypeOf(int[].class)).getComponentType().getType());
assertNull(TypeToken.of(Types.subtypeOf(Object.class)).getComponentType());
assertNull(TypeToken.of(Types.supertypeOf(Object[].class)).getComponentType());
}
内容来源于网络,如有侵权,请联系作者删除!