Compatibility Note: Methods may be added to this interface in future releases of the platform.
- Since:
- 1.6
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptionReturns the element corresponding to a type.asMemberOf(DeclaredType containing, Element element) Returns the type of an element when that element is viewed as a member of, or otherwise directly contained by, a given type.Returns the class of a boxed value of the primitive type argument.Applies capture conversion to a type.booleancontains(TypeMirror t1, TypeMirror t2) Tests whether one type argument contains another.List<? extends TypeMirror> Returns the direct supertypes of a type.Returns the erasure of a type.getArrayType(TypeMirror componentType) Returns an array type with the specified component type.getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs) Returns the type corresponding to a type element and actual type arguments.getDeclaredType(DeclaredType containing, TypeElement typeElem, TypeMirror... typeArgs) Returns the type corresponding to a type element and actual type arguments, given a containing type of which it is a member.Returns a pseudo-type used where no actual type is appropriate.Returns the null type.getPrimitiveType(TypeKind kind) Returns a primitive type.getWildcardType(TypeMirror extendsBound, TypeMirror superBound) Returns a new wildcard type.booleanisAssignable(TypeMirror t1, TypeMirror t2) Tests whether one type is assignable to another.booleanisSameType(TypeMirror t1, TypeMirror t2) Tests whether twoTypeMirrorobjects represent the same type.booleanTests whether the signature of one method is a subsignature of another.booleanisSubtype(TypeMirror t1, TypeMirror t2) Tests whether one type is a subtype of another.Returns the type (a primitive type) of unboxed values of a given type.
- 
Method Details- 
asElementReturns the element corresponding to a type. The type may be one of:- a DeclaredType
- a TypeVariable
- a pseudo-type for a package or module
 nullif the type is not one with a corresponding element. Types without corresponding elements include:- Parameters:
- t- the type to map to an element
- Returns:
- the element corresponding to the given type
 
- a 
- 
isSameTypeTests whether twoTypeMirrorobjects represent the same type.Caveat: if either of the arguments to this method represents a wildcard, this method will return false. As a consequence, a wildcard is not the same type as itself. This might be surprising at first, but makes sense once you consider that an example like this must be rejected by the compiler: List<?> list = new ArrayList<Object>();list.add(list.get(0));Since annotations are only meta-data associated with a type, the set of annotations on either argument is not taken into account when computing whether or not two TypeMirrorobjects are the same type. In particular, twoTypeMirrorobjects can have different annotations and still be considered the same.- Parameters:
- t1- the first type
- t2- the second type
- Returns:
- trueif and only if the two types are the same
 
- 
isSubtypeTests whether one type is a subtype of another. Any type is considered to be a subtype of itself.- Parameters:
- t1- the first type
- t2- the second type
- Returns:
- trueif and only if the first type is a subtype of the second
- Throws:
- IllegalArgumentException- if given a type for an executable, package, or module
- See Java Language Specification:
- 
4.10 Subtyping
 
- 
isAssignableTests whether one type is assignable to another.- Parameters:
- t1- the first type
- t2- the second type
- Returns:
- trueif and only if the first type is assignable to the second
- Throws:
- IllegalArgumentException- if given a type for an executable, package, or module
- See Java Language Specification:
- 
5.2 Assignment Contexts
 
- 
containsTests whether one type argument contains another.- Parameters:
- t1- the first type
- t2- the second type
- Returns:
- trueif and only if the first type contains the second
- Throws:
- IllegalArgumentException- if given a type for an executable, package, or module
- See Java Language Specification:
- 
4.5.1 Type Arguments of Parameterized Types
 
- 
isSubsignatureTests whether the signature of one method is a subsignature of another.- Parameters:
- m1- the first method
- m2- the second method
- Returns:
- trueif and only if the first signature is a subsignature of the second
- See Java Language Specification:
- 
8.4.2 Method Signature
 
- 
directSupertypesReturns the direct supertypes of a type. The interface types, if any, will appear last in the list. For an interface type with no direct super-interfaces, a type mirror representingjava.lang.Objectis returned. The typejava.lang.Objecthas no direct supertype (JLS 8.1.4, 8.1.5) so an empty list is returned for the direct supertypes of a type mirror representingjava.lang.Object.- Parameters:
- t- the type being examined
- Returns:
- the direct supertypes, or an empty list if none
- Throws:
- IllegalArgumentException- if given a type for an executable, package, or module
- See Java Language Specification:
- 
4.10 Subtyping
 
- 
erasureReturns the erasure of a type.- Parameters:
- t- the type to be erased
- Returns:
- the erasure of a type
- Throws:
- IllegalArgumentException- if given a type for a package or module
- See Java Language Specification:
- 
4.6 Type Erasure
 
- 
boxedClassReturns the class of a boxed value of the primitive type argument. That is, boxing conversion is applied.- Parameters:
- p- the primitive type to be converted
- Returns:
- the class of a boxed value of the primitive type argument
- See Java Language Specification:
- 
5.1.7 Boxing Conversion
 
- 
unboxedTypeReturns the type (a primitive type) of unboxed values of a given type. That is, unboxing conversion is applied.- Parameters:
- t- the type to be unboxed
- Returns:
- the type of an unboxed value of type t
- Throws:
- IllegalArgumentException- if the given type has no unboxing conversion
- See Java Language Specification:
- 
5.1.8 Unboxing Conversion
 
- 
captureApplies capture conversion to a type.- Parameters:
- t- the type to be converted
- Returns:
- the result of applying capture conversion
- Throws:
- IllegalArgumentException- if given a type for an executable, package, or module
- See Java Language Specification:
- 
5.1.10 Capture Conversion
 
- 
getPrimitiveTypeReturns a primitive type.- Parameters:
- kind- the kind of primitive type to return
- Returns:
- a primitive type
- Throws:
- IllegalArgumentException- if- kindis not a primitive kind
 
- 
getNullTypeNullType getNullType()Returns the null type. This is the type ofnull.- Returns:
- the null type
 
- 
getNoTypeReturns a pseudo-type used where no actual type is appropriate. The kind of type to return may be eitherVOIDorNONE.To get the pseudo-type corresponding to a package or module, call asType()on the element modeling the package or module. Names can be converted to elements for packages or modules usingElements.getPackageElement(CharSequence)orElements.getModuleElement(CharSequence), respectively.- Parameters:
- kind- the kind of type to return
- Returns:
- a pseudo-type of kind VOIDorNONE
- Throws:
- IllegalArgumentException- if- kindis not valid
 
- 
getArrayTypeReturns 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
 
- 
getWildcardTypeReturns a new wildcard type. Either of the wildcard's bounds may be specified, or neither, but not both.- Parameters:
- extendsBound- the extends (upper) bound, or- nullif none
- superBound- the super (lower) bound, or- nullif none
- Returns:
- a new wildcard type
- Throws:
- IllegalArgumentException- if bounds are not valid
 
- 
getDeclaredTypeReturns the type corresponding to a type element and actual type arguments. Given the type element forSetand the type mirror forString, for example, this method may be used to get the parameterized typeSet<String>.The number of type arguments must either equal the number of the type element's formal type parameters, or must be zero. If zero, and if the type element is generic, then the type element's raw type is returned. If a parameterized type is being returned, its type element 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, TypeElement, TypeMirror...).- Parameters:
- typeElem- the type element
- typeArgs- the actual type arguments
- Returns:
- the type corresponding to a type element and actual type arguments
- Throws:
- IllegalArgumentException- if too many or too few type arguments are given, or if an inappropriate type argument or type element is provided
 
- 
getDeclaredTypeReturns the type corresponding to a type element and actual type 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(TypeElement, 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 typeElem's formal type parameters. If it is not parameterized or if it isnull, this method is equivalent togetDeclaredType(typeElem, typeArgs).- Parameters:
- containing- the containing type, or- nullif none
- typeElem- the type element
- typeArgs- the actual type arguments
- Returns:
- the type corresponding to the type element 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, type element, or containing type is provided
 
- 
asMemberOfReturns the type of an element when that element is viewed as a member of, or otherwise directly contained by, a given type. For example, when viewed as a member of the parameterized typeSet<String>, theSet.addmethod is anExecutableTypewhose parameter is of typeString.- Parameters:
- containing- the containing type
- element- the element
- Returns:
- the type of the element as viewed from the containing type
- Throws:
- IllegalArgumentException- if the element is not a valid one for the given type
 
 
-