Interface Type
-
- 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
inttype exists even if it is not declared in any Java source file, while thejava.lang.Stringtype 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 applyingStringtoList<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
extendsclause 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
Twhen 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 classType.Kind
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default ArrayTypeasArray()Returns this type as an array type.default ClassTypeasClass()Returns this type as a class type.default DeclarationInfoasDeclaration()Returns this annotation target as a declaration.default ParameterizedTypeasParameterizedType()Returns this type as a parameterized type.default PrimitiveTypeasPrimitive()Returns this type as a primitive type.default TypeasType()Returns this annotation target as a type.default TypeVariableasTypeVariable()Returns this type as a type variable.default VoidTypeasVoid()Returns this type as the void pseudo-type.default WildcardTypeasWildcardType()Returns this type as a wildcard type.default booleanisArray()Returns whether this type is an array type.default booleanisClass()Returns whether this type is a class type.default booleanisDeclaration()Returns whether this annotation target is a declaration.default booleanisParameterizedType()Returns whether this type is a parameterized type.default booleanisPrimitive()Returns whether this type is a primitive type.default booleanisType()Returns whether this annotation target is a type.default booleanisTypeVariable()Returns whether this type is a type variable.default booleanisVoid()Returns whether this type is the void pseudo-type.default booleanisWildcardType()Returns whether this type is a wildcard type.Type.Kindkind()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:AnnotationTargetReturns whether this annotation target is a declaration.- Specified by:
isDeclarationin interfaceAnnotationTarget- Returns:
trueif this is a declaration,falseotherwise
-
isType
default boolean isType()
Description copied from interface:AnnotationTargetReturns whether this annotation target is a type.- Specified by:
isTypein interfaceAnnotationTarget- Returns:
trueif this is a type,falseotherwise
-
asDeclaration
default DeclarationInfo asDeclaration()
Description copied from interface:AnnotationTargetReturns this annotation target as a declaration.- Specified by:
asDeclarationin interfaceAnnotationTarget- Returns:
- this declaration, never
null
-
asType
default Type asType()
Description copied from interface:AnnotationTargetReturns this annotation target as a type.- Specified by:
asTypein interfaceAnnotationTarget- Returns:
- this type, never
null
-
isVoid
default boolean isVoid()
Returns whether this type is the void pseudo-type.- Returns:
trueif this is void,falseotherwise
-
isPrimitive
default boolean isPrimitive()
Returns whether this type is a primitive type.- Returns:
trueif this is a primitive type,falseotherwise
-
isClass
default boolean isClass()
Returns whether this type is a class type.- Returns:
trueif this is a class type,falseotherwise
-
isArray
default boolean isArray()
Returns whether this type is an array type.- Returns:
trueif this is an array type,falseotherwise
-
isParameterizedType
default boolean isParameterizedType()
Returns whether this type is a parameterized type.- Returns:
trueif this is a parameterized type,falseotherwise
-
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:
trueif this is a primitive type,falseotherwise
-
isWildcardType
default boolean isWildcardType()
Returns whether this type is a wildcard type.- Returns:
trueif this is a wildcard type,falseotherwise
-
asVoid
default VoidType asVoid()
Returns this type as the void pseudo-type.- Returns:
- this void type, never
null - Throws:
IllegalStateException- ifisVoid()returnsfalse
-
asPrimitive
default PrimitiveType asPrimitive()
Returns this type as a primitive type.- Returns:
- this primitive type, never
null - Throws:
IllegalStateException- ifisPrimitive()returnsfalse
-
asClass
default ClassType asClass()
Returns this type as a class type.- Returns:
- this class type, never
null - Throws:
IllegalStateException- ifisClass()returnsfalse
-
asArray
default ArrayType asArray()
Returns this type as an array type.- Returns:
- this array type, never
null - Throws:
IllegalStateException- ifisArray()returnsfalse
-
asParameterizedType
default ParameterizedType asParameterizedType()
Returns this type as a parameterized type.- Returns:
- this parameterized type, never
null - Throws:
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:
IllegalStateException- ifisTypeVariable()returnsfalse
-
asWildcardType
default WildcardType asWildcardType()
Returns this type as a wildcard type.- Returns:
- this wildcard type, never
null - Throws:
IllegalStateException- ifisWildcardType()returnsfalse
-
-