While a TypeElement represents a class or interface
element, a DeclaredType represents a class
or interface type, the latter being a use
(or invocation) of the former.
The distinction is most apparent with generic types,
for which a single element can define a whole
family of types. For example, the element
java.util.Set corresponds to the parameterized types
java.util.Set<String> and java.util.Set<Number>
(and many others), and to the raw type java.util.Set.
Each method of this interface that returns a list of elements will return them in the order that is natural for the underlying source of program information. For example, if the underlying source of information is Java source code, then the elements will be returned in source code order.
API Note
The represented class or interface may have a reference representation (either source code or executable output). Multiple classes and interfaces can share the same reference representation backing construct. For example, multiple classes and interfaces can be declared in the same source file, including, but not limited to:
In the context of annotation processing, a type element can be:
DeclaredType
| Modifier and Type | Method and Description |
|---|---|
| public TypeMirror | Returns: the type defined by this type elementRedeclares javax. Returns the type defined by this class or interface element, returning the prototypical type for an element representing a generic type. |
| public List | Returns: the enclosed elements in proper order, or an empty list if noneRedeclares javax. Returns the fields, methods, constructors, record components, and member classes and interfaces that are directly declared in this class or interface. |
| public Element | Returns: the package of a top-level class or interface, the immediately lexically enclosing element for a nested class or interfaceRedeclares javax. Returns the package of a top-level class or interface and returns the immediately lexically enclosing element for a nested class or interface. |
| public List | Returns: the interface types directly implemented by this class or extended by this interface, or an empty list if there are noneReturns the interface types directly implemented by this class or extended by this interface. |
| public NestingKind | Returns: the nesting kind of this class or interface elementReturns the nesting kind of this class or interface element. |
| public default List | Returns: the permitted classes, or an empty list if there are noneReturns the permitted classes of this class or interface element in declaration order. |
| public Name | Returns: the fully qualified name of this class or interface, or an empty name if noneRedeclares javax. Returns the fully qualified name of this class or interface element. |
| public default List | Returns: the record components, or an empty list if there are noneReturns the record components of this class or interface element in declaration order. |
| public Name | Returns: the simple name of this class or interface, an empty name for an anonymous classRedeclares javax. Returns the simple name of this class or interface element. |
| public TypeMirror | Returns: the direct superclass, or aNoType if there is noneReturns the direct superclass of this class or interface element. |
| public List | Returns: the formal type parameters, or an empty list if there are noneRedeclares javax. Returns the formal type parameters of this class or interface element in declaration order. |
| asType | back to summary |
|---|---|
| public TypeMirror asType() Redeclares javax. Returns the type defined by this class or interface element, returning the prototypical type for an element representing a generic type. A generic element defines a family of types, not just one.
If this is a generic element, a prototypical type is
returned which has the element's invocation on the
type variables corresponding to its own formal type parameters.
For example,
for the generic class element API Note The
| |
| getEnclosedElements | back to summary |
|---|---|
| public List Redeclares javax. Returns the fields, methods, constructors, record components,
and member classes and interfaces that are directly declared in
this class or interface.
This includes any mandated elements such as the (implicit) default constructor
and the implicit API Note As a particular instance of the general accuracy requirements and the ordering behavior required of this interface, the list of enclosed elements will be returned in the natural order for the originating source of information about the class or interface. For example, if the information about the class or interface is originating from a source file, the elements will be returned in source code order. (However, in that case the ordering of implicitly declared elements, such as default constructors, is not specified.)
| |
| getEnclosingElement | back to summary |
|---|---|
| public Element getEnclosingElement() Redeclares javax. Returns the package of a top-level class or interface and returns the immediately lexically enclosing element for a nested class or interface. | |
| getInterfaces | back to summary |
|---|---|
| public List Returns the interface types directly implemented by this class or extended by this interface.
| |
| getNestingKind | back to summary |
|---|---|
| public NestingKind getNestingKind() Returns the nesting kind of this class or interface element.
| |
| getPermittedSubclasses | back to summary |
|---|---|
| public default List Returns the permitted classes of this class or interface element in declaration order. Note that for an interface, permitted subclasses and subinterfaces can be returned. Implementation Specification The default implementations of this method returns an empty and unmodifiable list.
| |
| getQualifiedName | back to summary |
|---|---|
| public Name getQualifiedName() Redeclares javax. Returns the fully qualified name of this class or interface element. More precisely, it returns the canonical name. For local, and anonymous classes, which do not have canonical names, an empty name is returned. The name of a generic class or interface does not include any reference
to its formal type parameters.
For example, the fully qualified name of the interface
| |
| getRecordComponents | back to summary |
|---|---|
| public default List Returns the record components of this class or interface element in declaration order. Implementation Specification The default implementations of this method returns an empty and unmodifiable list.
| |
| getSimpleName | back to summary |
|---|---|
| public Name getSimpleName() Redeclares javax. Returns the simple name of this class or interface element. For an anonymous class, an empty name is returned. | |
| getSuperclass | back to summary |
|---|---|
| public TypeMirror getSuperclass() Returns the direct superclass of this class or interface element.
If this class or interface element represents an interface or the class
| |
| getTypeParameters | back to summary |
|---|---|
| public List Redeclares javax. Returns the formal type parameters of this class or interface element in declaration order.
| |