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 GenericArrayType
arrayOf(Type componentType)
Returns an array type whose elements are all instances ofcomponentType
.static ParameterizedType
collectionOf(Type elementType)
Returns a type modelling aCollection
whose elements are of typeelementType
.static Type
javaxProviderOf(Type type)
Returns a type modelling aProvider
that provides elements of typeelementType
.static ParameterizedType
listOf(Type elementType)
Returns a type modelling aList
whose elements are of typeelementType
.static ParameterizedType
mapOf(Type keyType, Type valueType)
Returns a type modelling aMap
whose keys are of typekeyType
and whose values are of typevalueType
.static ParameterizedType
newParameterizedType(Type rawType, Type... typeArguments)
Returns a new parameterized type, applyingtypeArguments
torawType
.static ParameterizedType
newParameterizedTypeWithOwner(Type ownerType, Type rawType, Type... typeArguments)
Returns a new parameterized type, applyingtypeArguments
torawType
and enclosed byownerType
.static ParameterizedType
providerOf(Type providedType)
Returns a type modelling aProvider
that provides elements of typeelementType
.static ParameterizedType
setOf(Type elementType)
Returns a type modelling aSet
whose elements are of typeelementType
.static WildcardType
subtypeOf(Type bound)
Returns a type that represents an unknown type that extendsbound
.static WildcardType
supertypeOf(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, applyingtypeArguments
torawType
. The returned type does not have an owner type.- Returns:
- a
serializable
parameterized type.
-
newParameterizedTypeWithOwner
public static ParameterizedType newParameterizedTypeWithOwner(Type ownerType, Type rawType, Type... typeArguments)
Returns a new parameterized type, applyingtypeArguments
torawType
and enclosed byownerType
.- Returns:
- a
serializable
parameterized type.
-
arrayOf
public static GenericArrayType arrayOf(Type componentType)
Returns an array type whose elements are all instances ofcomponentType
.- Returns:
- a
serializable
generic array type.
-
subtypeOf
public static WildcardType subtypeOf(Type bound)
Returns a type that represents an unknown type that extendsbound
. For example, ifbound
isCharSequence.class
, this returns? extends CharSequence
. Ifbound
isObject.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, ifbound
isString.class
, this returns? super String
.
-
listOf
public static ParameterizedType listOf(Type elementType)
Returns a type modelling aList
whose elements are of typeelementType
.- Returns:
- a
serializable
parameterized type.
-
collectionOf
public static ParameterizedType collectionOf(Type elementType)
Returns a type modelling aCollection
whose elements are of typeelementType
.- Returns:
- a
serializable
parameterized type.
-
setOf
public static ParameterizedType setOf(Type elementType)
Returns a type modelling aSet
whose elements are of typeelementType
.- Returns:
- a
serializable
parameterized type.
-
mapOf
public static ParameterizedType mapOf(Type keyType, Type valueType)
Returns a type modelling aMap
whose keys are of typekeyType
and whose values are of typevalueType
.- Returns:
- a
serializable
parameterized type.
-
providerOf
public static ParameterizedType providerOf(Type providedType)
Returns a type modelling aProvider
that provides elements of typeelementType
.- Returns:
- a
serializable
parameterized type.
-
javaxProviderOf
public static Type javaxProviderOf(Type type)
Returns a type modelling aProvider
that provides elements of typeelementType
.- Returns:
- a
serializable
parameterized type.
-
-