public interface Type extends AnnotationTarget
For example, the int
type exists even if it is not declared in any Java source file, while
the java.lang.String
type is declared by the class of the same name. Array types,
such as int[]
or String[][]
, are not declared anywhere either, but their
element types may be. A generic class, such as java.util.List
, declares a raw type
of the same name, but it does not declare the parameterized types, such as List<String>
.
Parameterized types are created by applying type arguments to generic classes. For example,
the List<String>
type is created by applying String
to List<T>
.
Types occur on many places. A field has a type, a method has a return type, a method parameter
has a type, even the extends
clause in a class declaration contains a type.
Occurences of types may be annotated.
Types are:
int
String
int[]
or String[][]
List<String>
T
when used in a class that declares a type parameter T
List<? extends Number>
Modifier and Type | Interface and Description |
---|---|
static class |
Type.Kind |
Modifier and Type | Method and Description |
---|---|
default ArrayType |
asArray()
Returns this type as an array type.
|
default ClassType |
asClass()
Returns this type as a class type.
|
default DeclarationInfo |
asDeclaration()
Returns this annotation target as a declaration.
|
default ParameterizedType |
asParameterizedType()
Returns this type as a parameterized type.
|
default PrimitiveType |
asPrimitive()
Returns this type as a primitive type.
|
default Type |
asType()
Returns this annotation target as a type.
|
default TypeVariable |
asTypeVariable()
Returns this type as a type variable.
|
default VoidType |
asVoid()
Returns this type as the void pseudo-type.
|
default WildcardType |
asWildcardType()
Returns this type as a wildcard type.
|
default boolean |
isArray()
Returns whether this type is an array type.
|
default boolean |
isClass()
Returns whether this type is a class type.
|
default boolean |
isDeclaration()
Returns whether this annotation target is a declaration.
|
default boolean |
isParameterizedType()
Returns whether this type is a parameterized type.
|
default boolean |
isPrimitive()
Returns whether this type is a primitive type.
|
default boolean |
isType()
Returns whether this annotation target is a type.
|
default boolean |
isTypeVariable()
Returns whether this type is a type variable.
|
default boolean |
isVoid()
Returns whether this type is the void pseudo-type.
|
default boolean |
isWildcardType()
Returns whether this type is a wildcard type.
|
Type.Kind |
kind()
Returns the kind of this type.
|
annotation, annotations, annotations, hasAnnotation, hasAnnotation, repeatableAnnotation
default boolean isDeclaration()
AnnotationTarget
isDeclaration
in interface AnnotationTarget
true
if this is a declaration, false
otherwisedefault boolean isType()
AnnotationTarget
isType
in interface AnnotationTarget
true
if this is a type, false
otherwisedefault DeclarationInfo asDeclaration()
AnnotationTarget
asDeclaration
in interface AnnotationTarget
null
default Type asType()
AnnotationTarget
asType
in interface AnnotationTarget
null
default boolean isVoid()
true
if this is void, false
otherwisedefault boolean isPrimitive()
true
if this is a primitive type, false
otherwisedefault boolean isClass()
true
if this is a class type, false
otherwisedefault boolean isArray()
true
if this is an array type, false
otherwisedefault boolean isParameterizedType()
true
if this is a parameterized type, false
otherwisedefault boolean isTypeVariable()
true
if this is a primitive type, false
otherwisedefault boolean isWildcardType()
true
if this is a wildcard type, false
otherwisedefault VoidType asVoid()
null
java.lang.IllegalStateException
- if isVoid()
returns false
default PrimitiveType asPrimitive()
null
java.lang.IllegalStateException
- if isPrimitive()
returns false
default ClassType asClass()
null
java.lang.IllegalStateException
- if isClass()
returns false
default ArrayType asArray()
null
java.lang.IllegalStateException
- if isArray()
returns false
default ParameterizedType asParameterizedType()
null
java.lang.IllegalStateException
- if isParameterizedType()
returns false
default TypeVariable asTypeVariable()
null
java.lang.IllegalStateException
- if isTypeVariable()
returns false
default WildcardType asWildcardType()
null
java.lang.IllegalStateException
- if isWildcardType()
returns false