-
- All Superinterfaces:
AnnotationTarget
- All Known Subinterfaces:
ArrayType
,ClassType
,ParameterizedType
,PrimitiveType
,TypeVariable
,VoidType
,WildcardType
public interface Type extends AnnotationTarget
A type is used in a program source code, but does not have to be declared anywhere.For example, the
int
type exists even if it is not declared in any Java source file, while thejava.lang.String
type is declared by the class of the same name. Array types, such asint[]
orString[][]
, are not declared anywhere either, but their element types may be. A generic class, such asjava.util.List
, declares a raw type of the same name, but it does not declare the parameterized types, such asList<String>
. Parameterized types are created by applying type arguments to generic classes. For example, theList<String>
type is created by applyingString
toList<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:
- the void pseudo-type
- a primitive type, such as
int
- a class type, such as
String
- an array type, such as
int[]
orString[][]
- a parameterized type, such as
List<String>
- a type variable, such as
T
when used in a class that declares a type parameterT
- a wildcard type, such as the type argument in
List<? extends Number>
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Type.Kind
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method 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.-
Methods inherited from interface jakarta.enterprise.lang.model.AnnotationTarget
annotation, annotations, annotations, hasAnnotation, hasAnnotation, repeatableAnnotation
-
-
-
-
Method Detail
-
isDeclaration
default boolean isDeclaration()
Description copied from interface:AnnotationTarget
Returns whether this annotation target is a declaration.- Specified by:
isDeclaration
in interfaceAnnotationTarget
- Returns:
true
if this is a declaration,false
otherwise
-
isType
default boolean isType()
Description copied from interface:AnnotationTarget
Returns whether this annotation target is a type.- Specified by:
isType
in interfaceAnnotationTarget
- Returns:
true
if this is a type,false
otherwise
-
asDeclaration
default DeclarationInfo asDeclaration()
Description copied from interface:AnnotationTarget
Returns this annotation target as a declaration.- Specified by:
asDeclaration
in interfaceAnnotationTarget
- Returns:
- this declaration, never
null
-
asType
default Type asType()
Description copied from interface:AnnotationTarget
Returns this annotation target as a type.- Specified by:
asType
in interfaceAnnotationTarget
- Returns:
- this type, never
null
-
isVoid
default boolean isVoid()
Returns whether this type is the void pseudo-type.- Returns:
true
if this is void,false
otherwise
-
isPrimitive
default boolean isPrimitive()
Returns whether this type is a primitive type.- Returns:
true
if this is a primitive type,false
otherwise
-
isClass
default boolean isClass()
Returns whether this type is a class type.- Returns:
true
if this is a class type,false
otherwise
-
isArray
default boolean isArray()
Returns whether this type is an array type.- Returns:
true
if this is an array type,false
otherwise
-
isParameterizedType
default boolean isParameterizedType()
Returns whether this type is a parameterized type.- Returns:
true
if this is a parameterized type,false
otherwise
-
isTypeVariable
default boolean isTypeVariable()
Returns whether this type is a type variable. Type variables are also used to represent type parameters in declarations of parameterized types.- Returns:
true
if this is a primitive type,false
otherwise
-
isWildcardType
default boolean isWildcardType()
Returns whether this type is a wildcard type.- Returns:
true
if this is a wildcard type,false
otherwise
-
asVoid
default VoidType asVoid()
Returns this type as the void pseudo-type.- Returns:
- this void type, never
null
- Throws:
java.lang.IllegalStateException
- ifisVoid()
returnsfalse
-
asPrimitive
default PrimitiveType asPrimitive()
Returns this type as a primitive type.- Returns:
- this primitive type, never
null
- Throws:
java.lang.IllegalStateException
- ifisPrimitive()
returnsfalse
-
asClass
default ClassType asClass()
Returns this type as a class type.- Returns:
- this class type, never
null
- Throws:
java.lang.IllegalStateException
- ifisClass()
returnsfalse
-
asArray
default ArrayType asArray()
Returns this type as an array type.- Returns:
- this array type, never
null
- Throws:
java.lang.IllegalStateException
- ifisArray()
returnsfalse
-
asParameterizedType
default ParameterizedType asParameterizedType()
Returns this type as a parameterized type.- Returns:
- this parameterized type, never
null
- Throws:
java.lang.IllegalStateException
- ifisParameterizedType()
returnsfalse
-
asTypeVariable
default TypeVariable asTypeVariable()
Returns this type as a type variable. Type variables are also used to represent type parameters in declarations of parameterized types.- Returns:
- this type variable, never
null
- Throws:
java.lang.IllegalStateException
- ifisTypeVariable()
returnsfalse
-
asWildcardType
default WildcardType asWildcardType()
Returns this type as a wildcard type.- Returns:
- this wildcard type, never
null
- Throws:
java.lang.IllegalStateException
- ifisWildcardType()
returnsfalse
-
-