Package com.google.inject.util
Class Types
- java.lang.Object
-
- com.google.inject.util.Types
-
public final class Types extends Object
Static methods for working with types.- Since:
- 2.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static GenericArrayTypearrayOf(Type componentType)Returns an array type whose elements are all instances ofcomponentType.static ParameterizedTypecollectionOf(Type elementType)Returns a type modelling aCollectionwhose elements are of typeelementType.static TypejakartaProviderOf(Type type)Returns a type modelling aProviderthat provides elements of typeelementType.static TypejavaxProviderOf(Type type)Returns a type modelling aProviderthat provides elements of typeelementType.static ParameterizedTypelistOf(Type elementType)Returns a type modelling aListwhose elements are of typeelementType.static ParameterizedTypemapOf(Type keyType, Type valueType)Returns a type modelling aMapwhose keys are of typekeyTypeand whose values are of typevalueType.static ParameterizedTypenewParameterizedType(Type rawType, Type... typeArguments)Returns a new parameterized type, applyingtypeArgumentstorawType.static ParameterizedTypenewParameterizedTypeWithOwner(Type ownerType, Type rawType, Type... typeArguments)Returns a new parameterized type, applyingtypeArgumentstorawTypeand enclosed byownerType.static ParameterizedTypeproviderOf(Type providedType)Returns a type modelling aProviderthat provides elements of typeelementType.static ParameterizedTypesetOf(Type elementType)Returns a type modelling aSetwhose elements are of typeelementType.static WildcardTypesubtypeOf(Type bound)Returns a type that represents an unknown type that extendsbound.static WildcardTypesupertypeOf(Type bound)Returns a type that represents an unknown supertype ofbound.
-
-
-
Method Detail
-
newParameterizedType
public static ParameterizedType newParameterizedType(Type rawType, Type... typeArguments)
Returns a new parameterized type, applyingtypeArgumentstorawType. The returned type does not have an owner type.- Returns:
- a
serializableparameterized type.
-
newParameterizedTypeWithOwner
public static ParameterizedType newParameterizedTypeWithOwner(Type ownerType, Type rawType, Type... typeArguments)
Returns a new parameterized type, applyingtypeArgumentstorawTypeand enclosed byownerType.- Returns:
- a
serializableparameterized type.
-
arrayOf
public static GenericArrayType arrayOf(Type componentType)
Returns an array type whose elements are all instances ofcomponentType.- Returns:
- a
serializablegeneric array type.
-
subtypeOf
public static WildcardType subtypeOf(Type bound)
Returns a type that represents an unknown type that extendsbound. For example, ifboundisCharSequence.class, this returns? extends CharSequence. IfboundisObject.class, this returns?, which is shorthand for? extends Object.
-
supertypeOf
public static WildcardType supertypeOf(Type bound)
Returns a type that represents an unknown supertype ofbound. For example, ifboundisString.class, this returns? super String.
-
listOf
public static ParameterizedType listOf(Type elementType)
Returns a type modelling aListwhose elements are of typeelementType.- Returns:
- a
serializableparameterized type.
-
collectionOf
public static ParameterizedType collectionOf(Type elementType)
Returns a type modelling aCollectionwhose elements are of typeelementType.- Returns:
- a
serializableparameterized type.
-
setOf
public static ParameterizedType setOf(Type elementType)
Returns a type modelling aSetwhose elements are of typeelementType.- Returns:
- a
serializableparameterized type.
-
mapOf
public static ParameterizedType mapOf(Type keyType, Type valueType)
Returns a type modelling aMapwhose keys are of typekeyTypeand whose values are of typevalueType.- Returns:
- a
serializableparameterized type.
-
providerOf
public static ParameterizedType providerOf(Type providedType)
Returns a type modelling aProviderthat provides elements of typeelementType.- Returns:
- a
serializableparameterized type.
-
javaxProviderOf
public static Type javaxProviderOf(Type type)
Returns a type modelling aProviderthat provides elements of typeelementType.- Returns:
- a
serializableparameterized type.
-
jakartaProviderOf
public static Type jakartaProviderOf(Type type)
Returns a type modelling aProviderthat provides elements of typeelementType.- Returns:
- a
serializableparameterized type. - Since:
- 6.0
-
-