Interface Types
-
public interface Types
Utility methods for operating on types.- Since:
- 1.5
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ArrayType
getArrayType(TypeMirror componentType)
Returns an array type with the specified component type.DeclaredType
getDeclaredType(TypeDeclaration decl, TypeMirror... typeArgs)
Returns the type corresponding to a type declaration and actual type arguments.DeclaredType
getDeclaredType(DeclaredType containing, TypeDeclaration decl, TypeMirror... typeArgs)
Returns the type corresponding to a type declaration and actual arguments, given a containing type of which it is a member.TypeMirror
getErasure(TypeMirror t)
Returns the erasure of a type.PrimitiveType
getPrimitiveType(PrimitiveType.Kind kind)
Returns a primitive type.TypeVariable
getTypeVariable(TypeParameterDeclaration tparam)
Returns the type variable declared by a type parameter.VoidType
getVoidType()
Returns the pseudo-type representing the type ofvoid
.WildcardType
getWildcardType(Collection<ReferenceType> upperBounds, Collection<ReferenceType> lowerBounds)
Returns a new wildcard.boolean
isAssignable(TypeMirror t1, TypeMirror t2)
Tests whether one type is assignable to another.boolean
isSubtype(TypeMirror t1, TypeMirror t2)
Tests whether one type is a subtype of the another.
-
-
-
Method Detail
-
isSubtype
boolean isSubtype(TypeMirror t1, TypeMirror t2)
Tests whether one type is a subtype of the another. Any type is considered to be a subtype of itself.- Parameters:
t1
- the first typet2
- the second type- Returns:
true
if and only if the first type is a subtype of the second
-
isAssignable
boolean isAssignable(TypeMirror t1, TypeMirror t2)
Tests whether one type is assignable to another.- Parameters:
t1
- the first typet2
- the second type- Returns:
true
if and only if the first type is assignable to the second
-
getErasure
TypeMirror getErasure(TypeMirror t)
Returns the erasure of a type.- Parameters:
t
- the type to be erased- Returns:
- the erasure of the given type
-
getPrimitiveType
PrimitiveType getPrimitiveType(PrimitiveType.Kind kind)
Returns a primitive type.- Parameters:
kind
- the kind of primitive type to return- Returns:
- a primitive type
-
getVoidType
VoidType getVoidType()
Returns the pseudo-type representing the type ofvoid
.- Returns:
- the pseudo-type representing the type of
void
-
getArrayType
ArrayType getArrayType(TypeMirror componentType)
Returns an array type with the specified component type.- Parameters:
componentType
- the component type- Returns:
- an array type with the specified component type.
- Throws:
IllegalArgumentException
- if the component type is not valid for an array
-
getTypeVariable
TypeVariable getTypeVariable(TypeParameterDeclaration tparam)
Returns the type variable declared by a type parameter.- Parameters:
tparam
- the type parameter- Returns:
- the type variable declared by the type parameter
-
getWildcardType
WildcardType getWildcardType(Collection<ReferenceType> upperBounds, Collection<ReferenceType> lowerBounds)
Returns a new wildcard. Either the wildcards's upper bounds or lower bounds may be specified, or neither, but not both.- Parameters:
upperBounds
- the upper bounds of this wildcard, or an empty collection if nonelowerBounds
- the lower bounds of this wildcard, or an empty collection if none- Returns:
- a new wildcard
- Throws:
IllegalArgumentException
- if bounds are not valid
-
getDeclaredType
DeclaredType getDeclaredType(TypeDeclaration decl, TypeMirror... typeArgs)
Returns the type corresponding to a type declaration and actual type arguments. Given the declaration forString
, for example, this method may be used to get theString
type. It may then be invoked a second time, with the declaration forSet
, to make the parameterized typeSet<String>
.The number of type arguments must either equal the number of the declaration's formal type parameters, or must be zero. If zero, and if the declaration is generic, then the declaration's raw type is returned.
If a parameterized type is being returned, its declaration must not be contained within a generic outer class. The parameterized type
Outer<String>.Inner<Number>
, for example, may be constructed by first using this method to get the typeOuter<String>
, and then invokinggetDeclaredType(DeclaredType, TypeDeclaration, TypeMirror...)
.- Parameters:
decl
- the type declarationtypeArgs
- the actual type arguments- Returns:
- the type corresponding to the type declaration and actual type arguments
- Throws:
IllegalArgumentException
- if too many or too few type arguments are given, or if an inappropriate type argument or declaration is provided
-
getDeclaredType
DeclaredType getDeclaredType(DeclaredType containing, TypeDeclaration decl, TypeMirror... typeArgs)
Returns the type corresponding to a type declaration and actual arguments, given a containing type of which it is a member. The parameterized typeOuter<String>.Inner<Number>
, for example, may be constructed by first usinggetDeclaredType(TypeDeclaration, TypeMirror...)
to get the typeOuter<String>
, and then invoking this method.If the containing type is a parameterized type, the number of type arguments must equal the number of the declaration's formal type parameters. If it is not parameterized or if it is
null
, this method is equivalent togetDeclaredType(decl, typeArgs)
.- Parameters:
containing
- the containing type, ornull
if nonedecl
- the type declarationtypeArgs
- the actual type arguments- Returns:
- the type corresponding to the type declaration and actual type arguments, contained within the given type
- Throws:
IllegalArgumentException
- if too many or too few type arguments are given, or if an inappropriate type argument, declaration, or containing type is provided
-
-